
#include	"SysConfig.h"
#include	"Define.h"
#include	"Port.h"
#include	"Function.h"
#include	"Utill.h"
#include	"UI_Main.h"
#include	"Display.h"
#include	"USB.h"
#include	"Power.h"
#ifdef  MIC
#include	"MIC.h"
#endif
#ifdef  CD
#include	"CD.h"
#include	"CD_MECHA.h"
#endif
#ifdef  AV_CONTROLLER
#include	"AVController.h"
#endif
#ifdef  AUTO_GUIDE
#include	"AutoGuide.h"
#endif
#ifdef  LC786XXX
#include	"LC786XXX.h"

extern void AUDIO_SetMute(unsigned char ucDes);
extern unsigned char ucAUDIO_TelMute;
#ifdef  CD
extern void DECK_SetInit(void);
#endif

extern UI_PLAY_INFO		sUSB_PlayInfo;
extern UI_SCAN_MODE		ucUSB_Scan;
extern UI_RANDOM_MODE	ucUSB_Random;
extern UI_REPEAT_MODE	ucUSB_Repeat;
extern unsigned char	ucUSB_Resume;
extern unsigned short	usUSB_ScanFileNumber;
extern unsigned short	DRV_LC786XXX_FirmwareUpdate_ON;
extern LC786X_MEDIA_ID  ucLC786XXX_CurrentMediaID;
extern LC786X_MEDIA_STATUS  ucLC786XXX_USB_Status;
extern LC786X_MEDIA_STATUS  ucLC786XXX_SD_Status;
extern LC786X_MEDIA_STATUS  ucLC786XXX_NewMedia_Status;
extern LC786X_MEDIA_STATUS  ucLC786XXX_iPod_Status;
extern unsigned char  ucLC786XXX_PlayHour;
extern unsigned char  ucLC786XXX_PlayMin;
extern unsigned char  ucLC786XXX_PlaySec;
extern unsigned char  ucLC786XXX_UpdateStatus;
extern unsigned char  ucLC786XXX_UpdatePersent;
extern unsigned char  ucLC786XXX_FileStatus;
extern unsigned char  ucLC786XXX_FunctionStatus;
extern unsigned short usLC786XXX_PlayFileNo;
extern unsigned short usLC786XXX_PlayBitRate;
extern unsigned short usLC786XXX_USB_TotalFile;
extern unsigned short usLC786XXX_PlayFolderNo;
extern unsigned long  ulLC786XXX_USB_IdentificationCode;
extern unsigned long  ulLC786XXX_USB_IdentificationCodePreVious;
extern unsigned long	ulLC786XXX_PlaySerialNo;
extern void CPU_WatchDogEnable(void);

extern unsigned char	ucUSB_ErrorCode;

#ifdef  LC78696X
extern unsigned short	usLC786XXX_CDROM_TotalFolder;
extern unsigned short	usLC786XXX_CDROM_TotalFile;
extern unsigned char	ucLC786XXX_CDDA_ProgramTimeMin;
extern unsigned char	ucLC786XXX_CDDA_ProgramTimeSec;
extern unsigned char	ucLC786XXX_CDDA_ProgramTimeFrame;
extern unsigned char	ucLC786XXX_CDDA_AbsoluteTimeMin;
extern unsigned char	ucLC786XXX_CDDA_AbsoluteTimeSec;
extern unsigned char	ucLC786XXX_CDDA_AbsoluteTimeFrame;
extern unsigned char	ucLC796XXX_CDTextStatus;
extern unsigned char	ucLC786XXX_CDTextCharacterCode[8];
extern unsigned char	ucLC786XXX_CDTextLanguageCode[8];
extern unsigned char	ucLC786XXX_DiscAssistInfo;
extern LC786X_MEDIA_STATUS  ucLC786XXX_CDDA_Status;
extern LC786X_MEDIA_STATUS  ucLC786XXX_CDROM_Status;
extern LC786X_DISC_STATUS ucLC786XXX_DiscStatus;
extern LC786X_DISC_TYPE ucLC78696X_DiscType;
#endif

unsigned char ucLC786XXX_TextBuf[MEDIA_CHAR_SIZE];
extern unsigned char	ucUSB_FileName[MEDIA_CHAR_SIZE];
extern unsigned char	ucUSB_FileName_CharCode;
extern unsigned char	ucUSB_FolderName[MEDIA_CHAR_SIZE];
extern unsigned char	ucUSB_FolderName_CharCode;
extern unsigned char	ucUSB_ID3_Title[MEDIA_CHAR_SIZE];
extern unsigned char	ucUSB_ID3_Title_CharCode;
extern unsigned char	ucUSB_ID3_Artist[MEDIA_CHAR_SIZE];
extern unsigned char	ucUSB_ID3_Artist_CharCode;
extern unsigned char	ucUSB_ID3_Album[MEDIA_CHAR_SIZE];
extern unsigned char	ucUSB_ID3_Album_CharCode;
extern UI_INFO_MODE		ucUSB_DisplayInfo;
extern UI_ID3TAG_MODE	ucUSB_Display_ID3Tag;

#ifdef  CD

extern unsigned char	ucCD_ErrorCode;
extern UI_PLAY_INFO  sCD_PlayInfo;
extern UI_INFO_MODE		ucCD_Display_Info;
extern UI_ID3TAG_MODE	ucCD_Display_ID3Tag;
extern unsigned char ucCD_Resume;
extern CD_DISC_TYPE  ucCD_CurrentPlayDiscType;
extern UI_REPEAT_MODE	ucCD_Repeat;
extern UI_RANDOM_MODE	ucCD_Random;
extern UI_SCAN_MODE	ucCD_Scan;
extern unsigned short usCD_ScanFileNumber;

extern unsigned char	ucCD_FileName[MEDIA_CHAR_SIZE];
extern unsigned char	ucCD_FileName_CharCode;
extern unsigned char	ucCD_FolderName[MEDIA_CHAR_SIZE];
extern unsigned char	ucCD_FolderName_CharCode;
extern unsigned char	ucCD_ID3_Title[MEDIA_CHAR_SIZE];
extern unsigned char	ucCD_ID3_Title_CharCode;
extern unsigned char	ucCD_ID3_Artist[MEDIA_CHAR_SIZE];
extern unsigned char	ucCD_ID3_Artist_CharCode;
extern unsigned char	ucCD_ID3_Album[MEDIA_CHAR_SIZE];
extern unsigned char	ucCD_ID3_Album_CharCode;
extern unsigned char ucCD_ID3_AlbumArtist[MEDIA_CHAR_SIZE];
extern unsigned char ucCD_ID3_AlbumArtist_CharCode;
extern CD_STATUS	ucCD_Status;

extern void CD_SetTextStatus(unsigned char ucDes);
extern void CD_ClearTextStatus(unsigned char ucDes);
extern void CD_SetStatusFlag(unsigned char ucDes);
extern void CD_ClearStatusFlag(unsigned char ucDes);
extern unsigned char CD_RandomFileChange(unsigned char ucMode);

#endif

extern LC786X_ERROR_CODE  ucLC786XXX_CDDA_ErrorCode;
extern LC786X_ERROR_CODE  ucLC786XXX_CDROM_ErrorCode;
extern LC786X_ERROR_CODE  ucLC786XXX_USB_ErrorCode;

extern unsigned short ucLC786XXX_Send_WritePtr;
extern unsigned short ucLC786XXX_Send_SendPtr;
extern unsigned char ucLC786XXX_Receive_Ptr;
extern unsigned char ucLC786XXX_Receive_ReadPtr;
extern unsigned char ucLC786XXX_GetText_Status;
extern unsigned char ucLC786XXX_GetText_CharCode;
extern unsigned char ucLC786XXX_CurrentText_LangCode;
extern unsigned short usLC786XXX_GetText_Length;
extern unsigned char ucLC786XXX_SPI_ReceiveSeq;
extern unsigned char ucLC786XXX_SPI_SendSeq;
extern unsigned char ucLC786XXX_SPI_Mode;
extern void LC786XXX_CloseCommunication(void);
extern void	LC786XXX_OpenCommunication(void);

extern unsigned char ucDRV_LC786XXX_BusyTimer50msec;

extern unsigned char ucDISP_FolderName;
extern unsigned char ucDISP_FileName;

extern unsigned char  ucDECK_Mode;

extern unsigned char	ucDISP_FolderName_Timer50msec;
extern unsigned char	ucDISP_FileName_Timer50msec;

//////////////////////// Extern of DRV_LC786X.c ////////////////////////////////////////////////////////////////

extern unsigned char DRV_LC786XXX_SendBufferStatus(void);
extern unsigned char DRV_LC786XXX_ReadBufferStatus(void);
extern unsigned char DRV_LC786XXX_SerialIdle(void);

extern void DRV_LC786XXX_Delay(unsigned char ucCnt);
extern unsigned char DRV_LC786XXX_Set_PlaybackContentsMode(void);
extern unsigned char DRV_LC786XXX_Set_USBSD_ContentsMode(unsigned char ucMediaID, unsigned char ucOpt);
extern unsigned char DRV_LC786XXX_Set_CDDiscContentsMode(void);
extern unsigned char DRV_LC786XXX_Set_ExtensionString(void);
extern unsigned char DRV_LC786XXX_Set_CDPlayMode(void);
extern unsigned char DRV_LC786XXX_Set_FFFBMode(unsigned char ucMediaMode);
extern unsigned char DRV_LC786XXX_Set_HighBandRetrieverMode(void);
extern unsigned char DRV_LC786XXX_Set_HighBandRetrieverScale(void);
extern unsigned char DRV_LC786XXX_PlayOrder(void);
extern unsigned char DRV_LC786XXX_Set_Repeat(unsigned char ucMode);
#ifdef  IPOD
extern unsigned char DRV_LC786XXX_Set_iPodAccessoryInfoCapabilities(void);
extern unsigned char DRV_LC786XXX_Start_iPodAuthenticationProtcol(void);
extern unsigned char DRV_LC786XXX_Start_iPodAccessoryInterface(void);
extern unsigned char DRV_LC786XXX_Set_iPodExtraCurrent(void);
#endif
extern unsigned char DRV_LC786XXX_MediaSelect(LC786X_MEDIA_ID ucMediaID);
extern unsigned char DRV_LC786XXX_Suspend(unsigned char ucMediaID);
extern unsigned char DRV_LC786XXX_ClearInfomation(unsigned char ucOption);
extern unsigned char DRV_LC786XXX_Eject(void);
extern unsigned char DRV_LC786XXX_Load(void);
extern unsigned char DRV_LC786XXX_Stop(unsigned char ucMediaID, unsigned char ucMode);
extern unsigned char DRV_LC786XXX_StartUp(unsigned char ucMediaID, unsigned char ucMode);
extern unsigned char DRV_LC786XXX_Playback(LC786X_MEDIA_ID	ucMediaID, unsigned char ucMode);
extern unsigned char DRV_LC786XXX_PlayFileNumber(LC786X_MEDIA_ID ucMediaID, UI_PLAY_INFO sPlayInfo);
extern unsigned char DRV_LC786XXX_Skip_SkipFolder(unsigned char ucDirection);
extern unsigned char DRV_LC786XXX_FastForward_FastBack(unsigned char ucDirection);
extern unsigned char DRV_LC786XXX_Get_FirmwareVersion(void);
extern unsigned char DRV_LC786XXX_Get_DiscType(void);
extern unsigned char DRV_LC786XXX_Get_CDToc(unsigned char ucMode);
extern unsigned char DRV_LC786XXX_GetTotalMediaFile(unsigned char ucMediaID, unsigned char ucMode, unsigned short usFolderNumber);
extern unsigned char DRV_LC786XXX_GetCurrentMediaStatus(unsigned char ucMediaID);
extern unsigned char DRV_LC786XXX_GetCDTextInformation(void);
#ifdef  LC78696X
extern unsigned char DRV_LC78696X_PlayCDTrack_AbsoluteTime(UI_PLAY_INFO sPlayInfo);
extern unsigned char DRV_LC786XXX_GetCDTextData(unsigned char ucMode,unsigned char ucTrackNum,unsigned char ucBlockNum,unsigned short usStartAddr,unsigned char ucNum);
#endif
extern unsigned char DRV_LC786XXX_GetCurrentFileInformation(void);
extern unsigned char DRV_LC786XXX_GetCurrentMediaTextData(LC786X_TEXT_ID ucMode, unsigned char ucBlock, unsigned short usStAddr, unsigned char ucNumByte);
unsigned char DRV_LC786XXX_Get_FolderFileName(LC786X_MEDIA_ID ucMediaID, unsigned char ucMode, unsigned short ucFolderNo, unsigned short ucFileNo);
extern unsigned char DRV_LC786XXX_GetConvertFileNumber(void);
extern unsigned char DRV_LC786XXX_GetMemoryRemaining(void);
extern unsigned char DRV_LC786XXX_GetFileData(void);
extern unsigned char DRV_LC786XXX_DSPStandbyControl(unsigned char ucMode, unsigned char ucOption);
extern unsigned char DRV_LC786XXX_DSP_CPU_Activation(void);
extern unsigned char DRV_LC786XXX_FirmwareUpdateMode(void);
extern unsigned char DRV_LC786XXX_FirmwareUpdateCancel(void);
extern unsigned char DRV_LC786XXX_FirmwareUpdateStart(void);
extern unsigned char DRV_LC786XXX_ReadFileCheck(void)	;
extern unsigned char DRV_LC786XXX_ReadFileDump(void);
extern unsigned char DRV_LC786XXX_ServoSpindleKick(void);
extern unsigned short DRV_LC786XXX_WriteServoParameter(unsigned char ucBank, unsigned char ucCnt);
extern unsigned short DRV_LC786XXX_WriteServoCommandRegister(unsigned char ucCnt);
extern unsigned short DRV_LC786XXX_WriteServoRam(unsigned char ucCnt);
extern unsigned char DRV_LC786XXX_WriteAutoAdjustData(void);
extern unsigned char DRV_LC786XXX_WritePlaybackParameter(void);
extern unsigned char DRV_LC786XXX_WriteDSPRegister(void);
extern unsigned char DRV_LC786XXX_ReadServoParameter(void);
extern unsigned char DRV_LC786XXX_ReadServoCommandRegister(void);
extern unsigned char DRV_LC786XXX_ReadServoRAM(void);
extern unsigned char DRV_LC786XXX_ReadAutoAdjustData(void);
extern unsigned char DRV_LC786XXX_ReadPlaybackParameter(void);

#ifdef  LC786XXX_AUDIO
extern unsigned char DRV_LC786XXX_SelectSelectorOutput(void);
extern unsigned char DRV_LC786XXX_WriteEVRGain(unsigned char  Volume, unsigned char Fader, unsigned char Balance);
extern unsigned char DRV_LC786XXX_VOL_ControlCommand(unsigned char ucVol);
extern unsigned char DRV_LC786XXX_BalanceFadeControlCommand(unsigned char ucBalance, unsigned char ucFade);
extern unsigned char DRV_LC786XXX_WriteEQData(unsigned char ucBand, unsigned char ucFilter);
extern unsigned char DRV_LC786XXX_SaveEQFilter(void);
extern unsigned char DRV_LC786XXX_LoadEQFilter(void);
extern unsigned char DRV_LC786XXX_SelectEQFilter(unsigned char ucLoud, unsigned char ucBass, unsigned char ucMiddle, unsigned char ucTreble, unsigned char ucEQ);
#endif
/////////////////////End of Extern of DRV_LC786X.c///////////////////////////////////////////////////////////////////

extern void USB_SetTextStatus(unsigned char ucDes);
extern void USB_ClearTextStatus(unsigned char ucDes);
extern unsigned char USB_RandomFileChange(unsigned char ucMode);

extern unsigned char ucFUNC_Power;
///////////////////////////////// Internal Function ///////////////////////////////////////////////////////
void LC786XXX_GetTextStart(void);
unsigned char	ucLC786XXX_InitFailCnt;
unsigned char	ucLC786XXX_InitProcess;
unsigned short	ucLC786XXX_Process_10msecTimer;
unsigned short  usLC786XXX_InitUSB_10mecTimer;
unsigned char	ucLC786XXX_MediaStatusCheck_10msecTimer;
unsigned char	ucLC786XXX_InitializeComplete;
unsigned char 	ucLC786XXX_FileChangeRequest;
unsigned char 	ucLC786XXX_RandomFileChange;
unsigned char	ucLC786XXX_UpdateSeq;

#ifdef  LC786XXX_AUDIO
unsigned char	ucLC786XXX_FilterWrited;
unsigned char	ucLC786XXX_InitAudio;
#endif
unsigned char	ucLC786XXX_USB_Process;
unsigned char	ucLC786XXX_USB_Detect_Timer10msec;
unsigned char	ucLC786XXX_USB_DetectPort;
unsigned char	ucLC786XXX_USB_Detected;
unsigned char	ucLC786XXX_USB_PlayOrder;
#ifdef  LC78696X
unsigned char	ucLC786XXX_CD_Process;
unsigned char	ucLC786XXX_CD_PlayOrder;
unsigned char	ucLC786XXX_InitializeCDServo;
#endif

LC786X_TEXT_ID ucLC786XXX_GetText_Type;
unsigned char ucLC786XXX_GetText_Seq;
#define	LC786XXX_GTEXT_IDLE				0
#define	LC786XXX_GTEXT_TEXT_START		1
#define	LC786XXX_GTEXT_GET_DATA_R		8
#define	LC786XXX_GTEXT_GET_NEXT			9

unsigned char ucLC786XXX_TextInfoRead_Mode_BlockNo;

unsigned char ucLC786XXX_AudioBand;
unsigned char ucLC786XXX_AudioFilter;
unsigned short usLC786XXX_Update_10msecTimer;
unsigned char ucLC786XXX_GetText_10msecTimer;
unsigned char  ucLC786XXX_PlayOrder;

/////////////////////////////// Internal Function End ////////////////////////////////////////////////////
#ifdef  LC78696X

unsigned char DRV_LC786XXX_GetCDProcess(void)
{
	return(ucLC786XXX_CD_Process);
}
#endif
void DRV_LC786XXX_SetPlayOrder(unsigned char ucMode)
{
	ucLC786XXX_PlayOrder = ucMode;
	LOG_LC786("SetPlayOrder:%d",ucLC786XXX_PlayOrder);
}

unsigned char DRV_LC786XXX_GetPlayOrder(void)
{
	LOG_LC786("GetPlayOrder:%d",ucLC786XXX_PlayOrder);
	return(ucLC786XXX_PlayOrder);
}

#ifdef  LC78696X
void LC786XXX_SetEjectProcess(void)
{
	ucLC786XXX_CD_Process = LC786XXX_PROCESS_EJECT;
}
#endif

unsigned char LC786XXX_CurrentSoundOut(UI_FUNCTION ucFunc)
{
	unsigned char ucDes = 0;

	switch  (LC786XXX_GetMediaStatus(ucFunc))
	{
		case LC786X_MS_PLAYBACK:
		case LC786X_MS_PAUSE:
//		case LC786X_MS_FASTFORWARD:
//		case LC786X_MS_FASTBACK:
		case LC786X_MS_PLAYBACK_PLAYLIST:
		case LC786X_MS_PAUSE_PLAYLIST:
//		case LC786X_MS_FASTFORWARD_PLAYLIST:
//		case LC786X_MS_FASTBACK_PLAYLIST:
			ucDes = 1;
			break;
	}

	return(ucDes);
}

LC786X_MEDIA_STATUS LC786XXX_GetMediaStatus(UI_FUNCTION ucFunc)
{
	unsigned char ucStatus;
	
	#ifdef  CD
	if  (ucFunc == FUNC_CD)
	{
		if  (ucCD_CurrentPlayDiscType == CD_DISC_CDDA)
		{
			ucStatus = ucLC786XXX_CDDA_Status;
		}
		else
		{
			ucStatus = ucLC786XXX_CDROM_Status;
		}
	}
	#endif
	if  (ucFunc == FUNC_USB)
	{
		ucStatus = ucLC786XXX_USB_Status;
	}

	return(ucStatus);
}


LC786X_ERROR_CODE LC786XXX_GetErrorCode(LC786X_MEDIA_ID ucMediaID)
{
	unsigned char ucErrorCode = LC786X_EC_NoError;
	
	#ifdef  CD
	if  (ucMediaID == LC786X_CDDA)
	{
		ucErrorCode = ucLC786XXX_CDDA_ErrorCode;
	}
	if  (ucMediaID == LC786X_CDROM)
	{
		ucErrorCode = ucLC786XXX_CDROM_ErrorCode;
	}
	#endif
	if  (ucMediaID == LC786X_USB)
	{
		ucErrorCode = ucLC786XXX_USB_ErrorCode;
	}

	return(ucErrorCode);
}

unsigned char LC786XXX_USB_GetPlayStatus(void)
{
#if  1
	if  (ucLC786XXX_USB_Status < LC786X_MS_TOC_READ)
	{
		return(0);
	}
	return(1);
#else
	if  (
		(ucLC786XXX_USB_Status == LC786X_MS_STOP)
		|| (ucLC786XXX_USB_Status == LC786X_MS_STOP_NO_TOC)
		|| (ucLC786XXX_USB_Status == LC786X_MS_RESET_START)
		|| (ucLC786XXX_USB_Status == LC786X_MS_DEVICE_DISCONNECT)
		|| (ucLC786XXX_USB_Status == LC786X_MS_MASS_STORAGE_CONNECT)
		)
	{
		return(0);
	}
	return(1);
#endif
}

unsigned char ucLC786XXX_Sleep;

void LC786XXX_GoToSleep(void)
{
#ifndef  LC786_SLEEP_TEST
	if  (ucLC786XXX_Sleep == 1)
	{
		return;
	}
	DRV_LC786XXX_MediaSelect(0x00);
	DRV_LC786XXX_DSPStandbyControl(0x01, 0x01);
	ucLC786XXX_Sleep = 1;
//	#ifdef  LC78696X
//	ucLC786XXX_CD_Process = LC786XXX_PROCESS_IDLE;
//	#endif
//	ucLC786XXX_USB_Process = LC786XXX_PROCESS_IDLE;
#endif
}

#ifdef  LC786_SLEEP_TEST

unsigned char LC786XXX_GoToSleepOptional(unsigned char ucDes)
{
	if  (ucLC786XXX_Sleep == 1)
	{
		return(0);
	}
	DRV_LC786XXX_MediaSelect(0x00);
	DRV_LC786XXX_DSPStandbyControl(ucDes, 0x01);

	ucLC786XXX_Sleep = 1;
	return(1);
}

#endif

unsigned char LC786XXX_WakeUp(void)
{
	if  (ucLC786XXX_Sleep == 0)
	{
		return(0);
	}
	DRV_LC786XXX_DSP_CPU_Activation();
	ucLC786XXX_Sleep = 0;
	return(1);
}

void LC786XXX_StopProcess(void)
{
	ucLC786XXX_InitProcess = LC786XXX_INIT_IDLE;
	ucLC786XXX_InitializeComplete = 0;
	USB_ClearFastPlayFlag();
#ifdef  CD
	CD_ClearFastPlayFlag();
#endif
}

void LC786XXX_StartInitialize(void)
{
	unsigned char i;
	unsigned char ucUSB_Ins;
	unsigned char ucCnt;
		
	LC786XXX_CloseCommunication();
	ucLC786XXX_InitProcess = LC786XXX_INIT_START;
	ucLC786XXX_Process_10msecTimer = 0;
	ucLC786XXX_InitializeComplete = 0;
#ifdef  LC786XXX_AUDIO
	ucLC786XXX_InitAudio = 0;
#endif
	ucLC786XXX_InitFailCnt = 0;
	ucLC786XXX_UpdateSeq = 0;
#ifdef  LC78696X
	ucLC786XXX_CDDA_Status = LC786X_MS_RESET_START;
	ucLC786XXX_CDROM_Status = LC786X_MS_RESET_START;
#endif
	ucLC786XXX_USB_Status = LC786X_MS_RESET_START;
	ucLC786XXX_SD_Status = LC786X_MS_RESET_START;
	PO_LC786_CE = 0;
	PO_LC786_RST = 0;
	LC786XXX_OpenCommunication();
	ucDRV_LC786XXX_BusyTimer50msec = 2000/50;
}

void LC786XXX_CloseCommunication(void)
{
#ifdef  M16C_64G
	prcr = 0x04;
	s4c = 0x00;
	s34c2 = 0x00;
	prcr = 0x00;
	s4ic = 0x00;
	ifsr7 = 0;
///////////////////////////////////////////////////////
#endif
#ifdef  M16C_30PG
	s0tic = 0;
	u0mr = 0x00;
	u0c0 = 0x00;
	u0c1 = 0;
#endif
}

void LC786XXX_OpenCommunication(void)
{	
	ucLC786XXX_SPI_Mode = LC786XXX_SPI_IDLE;
	ucLC786XXX_SPI_ReceiveSeq = LC786XXX_RSPI_IDLE;
	ucLC786XXX_SPI_SendSeq = LC786XXX_SPI_S_IDLE;
	ucLC786XXX_Send_WritePtr = 0;
	ucLC786XXX_Send_SendPtr = 0;
	ucLC786XXX_Receive_Ptr = 0;
	ucLC786XXX_Receive_ReadPtr = 0;
	
#ifdef  M16C_64G
///////////////// Serial 4 //////////////////////////// Sanyo
	prcr = 0x04;	// Clearing the protect

	s4c = 0x00	// Internal synchronous clock select bit : Selecting f1SIO or f2SIO
		| 0x00	// SOUTi output disable bit : SOUTi output enabled
		| 0x08	// SI/Oi port select bit :SOUTi output, CLKi function serial interface enabled
		| 0x00	// CLK polarity select bit : Transmit data is output at rising edge of transfer clock and receive data is input at falling edge
		| 0x20	// Transfer direction select RW bit : MSB first
		| 0x40	// Synchronous clock RW select bit : Internal clock
		| 0x80; // SOUTi initial value set bit : "H" Output
	s4brg = 60;	// BRGi divides the count source by n + 1 where n = set value
	s34c2 = 0x00;	// SOUT3,4 output control bit : High-impedance
	
	prcr = 0x00;	//Protect on
	s4ic = 0x03;
	ifsr7 = 0;
///////////////////////////////////////////////////////
#endif
#ifdef  M16C_30PG
///////////////// Serial 0 //////////////////////////// Sanyo
//	u2tb	: Transmission data
//	u2rb : Reception data
	u0mr = 0x01;	// Serial I/O mode select bit[0,1,2] : (001) Clock synchronous serial I/O mode
	u0c0 = 0x98;	// UiBRG count source select bit [0,1] : (01) f8SIO is selected
					// Transmit register empty flag[3] : (1) No data present in transmit register(transmission completed)
					// Transfer format select bit[7] : (1) MSB First
	u0brg = 20;
	u0c1 = 0x01 | 0x04;
	u0smr2 = 0x00;
	u0smr3 = 0x00;
	u0smr4 = 0x00;
	s0tic = 0x04;
	u0irs = 1;
///////////////////////////////////////////////////////
#endif
}

void LC786XXX_Initialize(void)
{
	if  (ucLC786XXX_InitializeComplete == 1)
	{
		return;
	}
	if  (DRV_LC786XXX_SerialIdle() == 0)
	{
		return;
	}
	if  ((DRV_LC786XXX_SendBufferStatus() == 1) || (DRV_LC786XXX_ReadBufferStatus() == 1))
	{
		return;
	}
	switch  (ucLC786XXX_InitProcess)
	{
		case LC786XXX_INIT_IDLE:
			break;
		case LC786XXX_INIT_START:	// idle
			if  (ucLC786XXX_Process_10msecTimer == 0)
			{
				LOG_LC786("LC786XXX_INIT_START");
				PO_LC786_RST = 0;
				PWR_PowerControl(PWR_USB, 0);
				ucLC786XXX_Process_10msecTimer = 50/10;
				ucLC786XXX_InitProcess = LC786XXX_INIT_RESET;				
			}
			break;
		case LC786XXX_INIT_RESET:
			if  (ucLC786XXX_Process_10msecTimer == 0)
			{
				LOG_LC786("LC786XXX_INIT_RESET");
				if  (++ucLC786XXX_InitFailCnt > 10)
				{
					ucLC786XXX_InitProcess = LC786XXX_INIT_IDLE;
					return;
				}
				PO_LC786_RST = 1;
				ucLC786XXX_Process_10msecTimer = 1000/10;
				ucLC786XXX_InitProcess = LC786XXX_INIT_CK_BUSY;
			}
			break;
		case LC786XXX_INIT_CK_BUSY:
			if  (PI_LC786_BUSY == 1)	// OK
			{
				LOG_LC786("LC786XXX_INIT_CK_BUSY:OK");
				ucLC786XXX_InitProcess = LC786XXX_INIT_CK_RESET;
				DRV_LC786XXX_GetCurrentMediaStatus(0x00);
			#ifdef  CD
				DECK_SetInit();
			#endif
			}
			else	// Fail
			{
				if  (ucLC786XXX_Process_10msecTimer == 0)
				{
					LOG_LC786("LC786XXX_INIT_CK_BUSY:FAIL");
					PO_LC786_RST = 0;
					PWR_PowerControl(PWR_USB, 0);
					ucLC786XXX_Process_10msecTimer = 500/10;
					ucLC786XXX_InitProcess = LC786XXX_INIT_RESET;
				}
			}
			break;
		case LC786XXX_INIT_CK_RESET:
			if  (ucLC786XXX_USB_Status == LC786X_MS_RESET_START)
			{
				LOG_LC786("LC786XXX_INIT_CK_RESET");
				ucLC786XXX_InitProcess = LC786XXX_INIT_CK_DEVICE;
				DRV_LC786XXX_GetCurrentMediaStatus(0x00);
			}
			break;
		case LC786XXX_INIT_CK_DEVICE:
			if  (ucLC786XXX_USB_Status == LC786X_MS_RESET_START)	// NG
			{
				ucLC786XXX_InitProcess = LC786XXX_INIT_RESET;
				PO_LC786_RST = 0;
				PWR_PowerControl(PWR_USB, 0);
				ucLC786XXX_Process_10msecTimer = 500/10;
				LOG_LC786("LC786XXX_INIT_CK_DEVICE:NG");
			}
			else	// OK
			{
				LOG_LC786("LC786XXX_INIT_CK_DEVICE:OK");
			#ifdef  LC786XXX_AUDIO
				ucLC786XXX_InitProcess = LC786XXX_INIT_AUDIO;
				ucLC786XXX_AudioBand = 0;
				ucLC786XXX_AudioFilter = 0;
			#else
				ucLC786XXX_InitProcess = LC786XXX_INIT_SEQ_INIT;
			#endif
			}
			break;
		case LC786XXX_INIT_SEQ_INIT:
			LOG_LC786("LC786XXX_INIT_SEQ_INIT");
			DRV_LC786XXX_Set_PlaybackContentsMode();
			DRV_LC786XXX_SetPlayOrder(0x40);
			DRV_LC786XXX_PlayOrder();
			ucLC786XXX_InitProcess = LC786XXX_INIT_SEQ_INIT + 1;
			break;
		case LC786XXX_INIT_SEQ_INIT + 1:
			LOG_LC786("LC786XXX_INIT_SEQ_INIT1");
			DRV_LC786XXX_Set_Repeat(LC786X_RPT_ALL);
			DRV_LC786XXX_Set_USBSD_ContentsMode(0x03, 0x02 | 0x04);	// For USB
			ucLC786XXX_InitProcess = LC786XXX_INIT_SEQ_INIT + 2;
			break;
		case LC786XXX_INIT_SEQ_INIT + 2:
			LOG_LC786("LC786XXX_INIT_SEQ_INIT2");
			DRV_LC786XXX_Set_FFFBMode(0x02);
			DRV_LC786XXX_GetCurrentMediaStatus(0x00);
			ucLC786XXX_InitProcess = LC786XXX_INIT_SEQ_INIT + 3;
			break;
		case LC786XXX_INIT_SEQ_INIT + 3:
			LOG_LC786("LC786XXX_INIT_SEQ_INIT3");
		#ifdef  LC78696X
			DRV_LC786XXX_Set_CDDiscContentsMode();
			DRV_LC786XXX_Set_CDPlayMode();
			DRV_LC786XXX_Set_FFFBMode(0x00);	// For CD-DA
			DRV_LC786XXX_Set_FFFBMode(0x01);	// For CD-ROM
		#endif
			ucLC786XXX_InitProcess = LC786XXX_INIT_READ_RESULT;
			break;
		case LC786XXX_INIT_READ_RESULT:
			if  (ucLC786XXX_USB_Status == LC786X_MS_DEVICE_DISCONNECT)
			{				
				LOG_LC786("LC786XXX_INIT_READ_RESULT:OK");
				PWR_PowerControl(PWR_USB, 1);
				DRV_LC786XXX_Get_FirmwareVersion();
		//		DRV_LC786XXX_GetCurrentMediaStatus(0x00);
			#ifdef  LC78696X
				ucLC786XXX_InitProcess = LC786XXX_INIT_SERVO_PARAM_B1;
				ucLC786XXX_InitializeCDServo = 0;
			#else
				DRV_LC786XXX_GetCurrentMediaStatus(0x00);
				ucLC786XXX_InitProcess = LC786XXX_INIT_END;
				ucLC786XXX_Process_10msecTimer = 5000/10;//3000/10;
			#endif
			}
			if  (ucLC786XXX_USB_Status == LC786X_MS_RESET_START)
			{
				LOG_LC786("LC786XXX_INIT_READ_RESULT:NG");
				PO_LC786_RST = 0;
				PWR_PowerControl(PWR_USB, 0);
				ucLC786XXX_Process_10msecTimer = 500/10;
			}
			break;
		case LC786XXX_INIT_END:
			DRV_LC786XXX_GetCurrentMediaStatus(0x00);
		#if  1
			LOG_LC786("LC786XXX_INIT_END");
			ucLC786XXX_Process_10msecTimer = 0;
			ucLC786XXX_InitProcess = 0;
			ucLC786XXX_InitializeComplete = 1;
			usLC786XXX_InitUSB_10mecTimer = 5000/10;
		#ifdef  LC78696X
			LC786XXX_GoToSleep();
		#endif
		#else
			if  ((ucLC786XXX_Process_10msecTimer == 0)
				|| (ucLC786XXX_USB_Status == LC786X_MS_MASS_STORAGE_CONNECT))
			{
				LOG_LC786("LC786XXX_INIT_END");
				LOG_ACC("LC786XXX_INIT_END:%X", ucLC786XXX_USB_Status);
				ucLC786XXX_InitProcess = 0;
				ucLC786XXX_InitializeComplete = 1;
			#ifdef  LC78696X
				LC786XXX_GoToSleep();
			#endif
			}
			if  (ucLC786XXX_USB_Status == LC786X_MS_MASS_STORAGE_CONNECT)
			{
				ucLC786XXX_USB_Detected = 1;
				LOG_LC786("DETECTED");
			}
		#endif
			break;
		#ifdef  LC78696X
		case LC786XXX_INIT_SERVO_PARAM_B1:
			LOG_LC786("LC786XXX_INIT_SERVO_PARAM_B1");
			ucLC786XXX_InitializeCDServo = DRV_LC786XXX_WriteServoParameter(0, ucLC786XXX_InitializeCDServo);
			if  (ucLC786XXX_InitializeCDServo == 0)
			{
				ucLC786XXX_InitProcess = LC786XXX_INIT_SERVO_PARAM_B2;
			}
			break;
		case LC786XXX_INIT_SERVO_PARAM_B2:
			LOG_LC786("LC786XXX_INIT_SERVO_PARAM_B2");
			ucLC786XXX_InitializeCDServo = DRV_LC786XXX_WriteServoParameter(1, ucLC786XXX_InitializeCDServo);
			if  (ucLC786XXX_InitializeCDServo == 0)
			{
				ucLC786XXX_InitProcess = LC786XXX_INIT_SERVO_REG;
			}
			break;
		case LC786XXX_INIT_SERVO_REG:
			LOG_LC786("LC786XXX_INIT_SERVO_REG");
			ucLC786XXX_InitializeCDServo = DRV_LC786XXX_WriteServoCommandRegister(ucLC786XXX_InitializeCDServo);
			if  (ucLC786XXX_InitializeCDServo == 0)
			{
				ucLC786XXX_InitProcess = LC786XXX_INIT_SERVO_RAM;
			}
			break;
		case LC786XXX_INIT_SERVO_RAM:
			LOG_LC786("LC786XXX_INIT_SERVO_RAM");
			ucLC786XXX_InitializeCDServo = DRV_LC786XXX_WriteServoRam(ucLC786XXX_InitializeCDServo);
			if  (ucLC786XXX_InitializeCDServo == 0)
			{
				ucLC786XXX_InitProcess = LC786XXX_INIT_END;
				ucLC786XXX_Process_10msecTimer = 5000/10;//3000/10;
				DRV_LC786XXX_GetCurrentMediaStatus(0x00);
			}
			break;
		#endif
	#ifdef  LC786XXX_AUDIO
		case LC786XXX_INIT_AUDIO:
			DRV_LC786XXX_SelectSelectorOutput();	
			if  (ucLC786XXX_FilterWrited == 0)
			{
				ucLC786XXX_InitProcess = LC786XXX_INIT_AUDIO + 1;
				LOG_LC786("LC786XXX_INIT_AUDIO:Write");
			}
			else
			{
				ucLC786XXX_InitProcess = LC786XXX_INIT_SEQ_INIT;
				ucLC786XXX_InitAudio = 1;
				LOG_LC786("LC786XXX_INIT_AUDIO:Read");
				
			}
			break;
		case LC786XXX_INIT_AUDIO + 1:
			DRV_LC786XXX_WriteEQData(ucLC786XXX_AudioBand,ucLC786XXX_AudioFilter);

			if  (++ucLC786XXX_AudioFilter > 10)
			{
				ucLC786XXX_AudioFilter = 0;
				if  (++ucLC786XXX_AudioBand > 6)
				{
					ucLC786XXX_InitProcess = LC786XXX_INIT_AUDIO + 2;
				}
			}
			break;
		case LC786XXX_INIT_AUDIO + 2:
			DRV_LC786XXX_SaveEQFilter();
			ucLC786XXX_InitProcess = LC786XXX_INIT_SEQ_INIT;
			ucLC786XXX_InitAudio = 1;
			break;
		case LC786XXX_INIT_AUDIO + 5:
			DRV_LC786XXX_LoadEQFilter();
			ucLC786XXX_InitProcess = LC786XXX_INIT_AUDIO + 6;
			ucLC786XXX_Process_10msecTimer = 100/10;
			break;
		case LC786XXX_INIT_AUDIO + 6:
			if  (ucLC786XXX_Process_10msecTimer == 0)
			{
				ucLC786XXX_InitProcess = LC786XXX_INIT_SEQ_INIT;
				ucLC786XXX_InitAudio = 1;
				LOG_LC786("LC786XXX_INIT_AUDIO+6");
			}
			break;
	#endif
	}
}

void DRV_LC786XXX_FirmwareUpdate(void)
{
	switch	(ucLC786XXX_UpdateSeq)
	{
		case 0:
			if  (ucLC786XXX_USB_Status != LC786X_MS_DEVICE_DISCONNECT)
			{
			#ifdef	LC78696X
				LC786XXX_WakeUp();
			#endif
				AUDIO_MuteOn();
				ucLC786XXX_UpdateSeq = 1;
			}
			else
			{
				DRV_LC786XXX_FirmwareUpdate_ON = 0;	
				DISP_SetTempDisplayMode_3Sec(DISP_NoUSB);
			}
			break;
		case 1:
			DRV_LC786XXX_MediaSelect(LC786X_USB);
			ucLC786XXX_UpdateSeq = 2;
			break;
		case 2:
			DRV_LC786XXX_FirmwareUpdateMode();
			ucLC786XXX_UpdateSeq = 3;
			break;
		case 3:
			if  (ucLC786XXX_UpdateStatus == LC786X_MS_UPDATE_PREPARATION_ONGOING
				|| ucLC786XXX_UpdateStatus == LC786X_MS_FINISH_ERROR)	
			{	
				if  (ucLC786XXX_UpdateStatus == LC786X_MS_FINISH_ERROR)	
				{
					DRV_LC786XXX_FirmwareUpdate_ON = 0;
					ucLC786XXX_UpdateSeq = 0;
					AUDIO_MuteOff();
					DRV_LC786XXX_FirmwareUpdateCancel();
					DISP_SetTempDisplayMode_10Sec(DISP_NoFile);
				}
			}
			else if  (ucLC786XXX_UpdateStatus == LC786X_MS_WAITING_UPFATE )
			{	
				AUDIO_MuteOn();
				DRV_LC786XXX_FirmwareUpdateStart();
				ucLC786XXX_UpdateSeq = 4;	
			}
			break;
		case 4:
			if  (ucLC786XXX_UpdateStatus == LC786X_MS_VBUS_CUT_REQUEST)
			{
				PWR_PowerControl(PWR_USB, 0);
				
				ucLC786XXX_UpdateSeq = 5;	
				usLC786XXX_Update_10msecTimer = 3000/10;
			}
		#ifdef M16C_30PG
			else if (ucLC786XXX_UpdateStatus != LC786X_MS_EXECUTION_START)
			{
				ucLC786XXX_UpdateSeq = 6 ;
			}
		#else
			else if (ucLC786XXX_UpdateStatus == LC786X_MS_EXECUTION_START)
			{
				ucLC786XXX_UpdateSeq = 6 ;
			}
		#endif
			break;
		case 5:
			if  (usLC786XXX_Update_10msecTimer == 0)
			{
				PWR_PowerControl(PWR_USB, 1);
				ucLC786XXX_UpdateSeq = 6;
			}
			break;		
		case 6:
			if  (ucLC786XXX_UpdateStatus == LC786X_MS_EXECUTION_ONGOING)
			{
				
				ucLC786XXX_UpdateSeq = 7;
			}
			else if  ( ucLC786XXX_UpdateStatus == LC786X_MS_FINISH_ERROR )
			{
				DRV_LC786XXX_FirmwareUpdate_ON = 0;
				ucLC786XXX_UpdateSeq = 0;
				AUDIO_MuteOff();
				DRV_LC786XXX_FirmwareUpdateCancel();
				DISP_SetTempDisplayMode_10Sec(DISP_FirmwereUpdateError);
			}
			break;
		case 7:				
			if	( ucLC786XXX_UpdateStatus == LC786X_MS_FINISH_NORMAL
				|| ucLC786XXX_UpdateStatus == LC786X_MS_FINISH_ERROR )
			{
				if	( ucLC786XXX_UpdateStatus == LC786X_MS_FINISH_ERROR )
				{
					DRV_LC786XXX_FirmwareUpdate_ON = 0;
					ucLC786XXX_UpdateSeq = 0;
					AUDIO_MuteOff();
					DRV_LC786XXX_FirmwareUpdateCancel();
					DISP_SetTempDisplayMode_10Sec(DISP_FirmwereUpdateFail);
				}
				else
				{
					ucLC786XXX_UpdateSeq = 8;
					usLC786XXX_Update_10msecTimer = 5000/10;
					CPU_WatchDogEnable();
				}
			
			}
			break;
		case 8:
			if  (usLC786XXX_Update_10msecTimer == 0)
			{
			}
			break;
	}
}


void LC786XXX_ChangeToUSB(void)
{
	#ifdef  LC78696X
	ucLC786XXX_CD_PlayOrder = DRV_LC786XXX_GetPlayOrder();
	#endif
	ucLC786XXX_USB_Process = LC786XXX_PROCESS_MEDIA_CHANGE;
	#ifdef  CD
	ucLC786XXX_CD_Process = 0;
	#endif
	ucLC786XXX_MediaStatusCheck_10msecTimer = 0;
	ucLC786XXX_Process_10msecTimer = 100/10;

	#ifdef  LC78696X
	if  (LC786XXX_WakeUp() == 1)
	{
		ucLC786XXX_Process_10msecTimer = 500/10;
	}
	#endif
}

void LC786XXX_USBFunctionProcess(void)
{
	switch  (ucLC786XXX_USB_Process)
	{
		case LC786XXX_PROCESS_IDLE:
			break;
		case LC786XXX_PROCESS_CHECK_MOUNTED:
			LOG_LC786("LC786XXX_PROCESS_CHECK_MOUNTED:USB");
			if  ((ucLC786XXX_USB_Status == LC786X_MS_MASS_STORAGE_CONNECT)	// Mass Storage Connect
				|| (ucLC786XXX_USB_Status == LC786X_MS_STOP_NO_TOC))
			{	// for new USB
				ucLC786XXX_USB_PlayOrder = 0x40;
				DRV_LC786XXX_SetPlayOrder(ucLC786XXX_USB_PlayOrder);
				DRV_LC786XXX_Playback(LC786X_USB, 0x02);	// Mount Start
				ucLC786XXX_USB_Process = LC786XXX_PROCESS_WAIT_READING;
				ucLC786XXX_MediaStatusCheck_10msecTimer = 0;
				USB_SetStatus(USB_ST_READING);
			}
			else	// Resume or play
			{
				ucLC786XXX_USB_Process = LC786XXX_PROCESS_PLAY_REQUEST;
			}
			break;
		case LC786XXX_PROCESS_WAIT_READING:
			if  (
				(ucLC786XXX_USB_Status == LC786X_MS_PAUSE_AT_STARTUP)
				|| (ucLC786XXX_USB_Status == LC786X_MS_PAUSE) || (ucLC786XXX_USB_Status == LC786X_MS_STOP)
				|| (ucLC786XXX_USB_Status == 0x84)
				)
			{
				DRV_LC786XXX_GetTotalMediaFile(LC786X_USB,0x00,0x00);
				ucLC786XXX_USB_Process = LC786XXX_PROCESS_GET_TOTALFILE;
			}
			break;
		case LC786XXX_PROCESS_GET_TOTALFILE:
		//	ucLC786XXX_USB_Process = LC786XXX_PROCESS_NORMAL;
			if  (usLC786XXX_USB_TotalFile != 0)
			{
				ucLC786XXX_USB_Process = LC786XXX_PROCESS_PLAY_REQUEST;
			}
			break;
		case LC786XXX_PROCESS_PLAY_REQUEST:
			if  (ucAUDIO_TelMute == 1)
			{
				return;
			}
			LOG_LC786("LC786XXX_PROCESS_PLAY_REQUEST:USB");
			if  ((ucUSB_Resume == 1) && (ulLC786XXX_USB_IdentificationCode == ulLC786XXX_USB_IdentificationCodePreVious))
			{
				DRV_LC786XXX_PlayFileNumber(LC786X_USB, sUSB_PlayInfo);
				if  (ucUSB_Repeat == REPEAT_FILE)
				{
					DRV_LC786XXX_Set_Repeat(LC786X_RPT_FILE);
				}
				if  (ucUSB_Repeat == REPEAT_FOLDER)
				{
					DRV_LC786XXX_Set_Repeat(LC786X_RPT_FLD);
				}
			}
			else
			{
				DRV_LC786XXX_Playback(LC786X_USB, 0x00);
				sUSB_PlayInfo.FileNo = 1;
			}
			ucLC786XXX_USB_Process = LC786XXX_PROCESS_CHECK_PLAY;
			ulLC786XXX_USB_IdentificationCodePreVious = ulLC786XXX_USB_IdentificationCode;
			break;
		case LC786XXX_PROCESS_CHECK_PLAY:
			if  ((LC786XXX_GetMediaStatus(FUNC_USB) == LC786X_MS_PLAYBACK)
				|| (LC786XXX_GetMediaStatus(FUNC_USB) == LC786X_MS_PLAYBACK_PLAYLIST))
			{
				ucLC786XXX_USB_Process = LC786XXX_PROCESS_NORMAL;
			}
			break;
		case LC786XXX_PROCESS_MEDIA_CHANGE:
		#if  1
			if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
			{
				ucLC786XXX_USB_Process = LC786XXX_PROCESS_CHECK_MOUNTED;
			}
			else
			{
				if  (ucLC786XXX_Process_10msecTimer == 0)
				{
					DRV_LC786XXX_MediaSelect(LC786X_USB);
					ucLC786XXX_Process_10msecTimer = 1000/10;
				}
			}
		#else
			if  (ucLC786XXX_Process_10msecTimer == 0)
			{
				DRV_LC786XXX_MediaSelect(LC786X_USB);
				ucLC786XXX_Process_10msecTimer = 1000/10;
			}
			else
			{
				if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
				{
					ucLC786XXX_USB_Process = LC786XXX_PROCESS_CHECK_MOUNTED;
				}
				
			}
		#endif
			break;
	}
}

void LC786XXX_GetTextStart(void)
{
	ucLC786XXX_GetText_Seq = LC786XXX_GTEXT_TEXT_START;

	if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
	{
		ucLC786XXX_GetText_Type = LC786X_TEXT_TITLE;
	}
	else
	{
		ucLC786XXX_GetText_Type = LC786X_TEXT_FILE_NAME;
	}
	ucLC786XXX_FileStatus = 0;
	ucLC786XXX_GetText_10msecTimer = 100/10;
	LOG_LC786("LC786XXX_GetTextStart");
}

void LC786XXX_GetText_CopyText(unsigned char ucCharCode, unsigned char *ucData, unsigned char *ucBuf, unsigned short ucLen)
{
	memset(ucBuf, 0x00, MEDIA_CHAR_SIZE);
//	if  (ucCharCode == 0xF1)
//	{
//		UTILL_UTF8ToUnicode(ucData, ucBuf, ucLen, MEDIA_CHAR_SIZE);
//	}
//	else
	{
		memcpy(ucBuf,ucData,ucLen);
	}
}

#ifdef  FILE_SEARCH

unsigned char ucLC786_GetFileName;
#define	LC786XXX_GFILENAME_IDLE			0
#define	LC786XXX_GFILENAME_STATUS		1
#define	LC786XXX_GFILENAME_GET_DATA		2

unsigned short ucLC786_GetFileName_Num;
unsigned char  ucLC786_GetFileName_Timer10msec;

extern unsigned char ucLC786XXX_GetFileName_Status;
extern unsigned char	ucUSB_FileSearchName[MEDIA_CHAR_SIZE];
extern unsigned char	ucUSB_FileSearchName_CharCode;
#ifdef  CD
extern unsigned char	ucCD_FileSearchName[MEDIA_CHAR_SIZE];
extern unsigned char	ucCD_FileSearchName_CharCode;
#endif

void LC786XXX_GetFileNameStart(unsigned short ucNum)
{
	ucLC786_GetFileName_Num = ucNum;

	if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
	{
	}
	else
	{
		DRV_LC786XXX_Get_FolderFileName(LC786X_CURRENT, 0x00, 0x00, ucLC786_GetFileName_Num);
		ucLC786_GetFileName = LC786XXX_GFILENAME_STATUS;
		ucLC786_GetFileName_Timer10msec = 1000/10;
	}
}

void LC786XXX_FileSearchPlay(void)
{
	UI_PLAY_INFO	sPlayInfo;

	sPlayInfo.FolderNo = 0;
	sPlayInfo.FileNo = ucLC786_GetFileName_Num;
	sPlayInfo.Hour = 0;
	sPlayInfo.Min = 0;
	sPlayInfo.Sec = 0;

	if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
	{
		DRV_LC78696X_PlayCDTrack_AbsoluteTime(sPlayInfo);
	}
	else
	{
		DRV_LC786XXX_PlayFileNumber(ucLC786XXX_CurrentMediaID, sPlayInfo);
	}
}

void LC786XXX_FileSearch_CopyFileNameUSB(void)
{
	ucUSB_FileName_CharCode = ucUSB_FileSearchName_CharCode;
	LC786XXX_GetText_CopyText(ucUSB_FileName_CharCode, &ucUSB_FileSearchName[0], &ucUSB_FileName[0], usLC786XXX_GetText_Length);
}

#ifdef  CD
void LC786XXX_FileSearch_CopyFileNameCD(void)
{
	ucCD_FileName_CharCode = ucCD_FileSearchName_CharCode;
	LC786XXX_GetText_CopyText(ucCD_FileName_CharCode, &ucCD_FileSearchName[0], &ucCD_FileName[0], usLC786XXX_GetText_Length);
}
#endif

void LC786XXX_GetFileName_Save(void)
{
	if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
	{
	//	USB_SetTextStatus(UI_TEXT_READY_FILENAME);
		ucUSB_FileSearchName_CharCode = ucLC786XXX_GetText_CharCode;
		LC786XXX_GetText_CopyText(ucUSB_FileSearchName_CharCode, &ucLC786XXX_TextBuf[0], &ucUSB_FileSearchName[0], usLC786XXX_GetText_Length);
		ucLC786_GetFileName = LC786XXX_GFILENAME_IDLE;
		return;
	}
	
	if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
	{
	//	USB_SetTextStatus(UI_TEXT_READY_FILENAME);
		ucCD_FileSearchName_CharCode = ucLC786XXX_GetText_CharCode;
		LC786XXX_GetText_CopyText(ucCD_FileSearchName_CharCode, &ucLC786XXX_TextBuf[0], &ucCD_FileSearchName[0], usLC786XXX_GetText_Length);
		ucLC786_GetFileName = LC786XXX_GFILENAME_IDLE;
	}
}

void LC786XXX_GetFileName(void)
{
	switch  (ucLC786_GetFileName)
	{
		case LC786XXX_GFILENAME_IDLE:
			break;
		case LC786XXX_GFILENAME_STATUS:		
			if  (ucLC786XXX_GetFileName_Status == 0x02)	// OK
			{
				ucLC786_GetFileName = LC786XXX_GFILENAME_IDLE;
			}
			else  if  (ucLC786XXX_GetFileName_Status == 0x00)	// Absent
			{
				ucLC786_GetFileName = LC786XXX_GFILENAME_IDLE;
			}
			else	// Ongoing
			{
				if  (ucLC786_GetFileName_Timer10msec == 0)
				{
					DRV_LC786XXX_Get_FolderFileName(LC786X_CURRENT, 0x00, 0x00, ucLC786_GetFileName_Num);
					ucLC786_GetFileName_Timer10msec = 1000/10;
				}
			}
			break;
	}
}
#endif

void LC786XXX_GetText_SelectNext(void)
{
	unsigned char ucCurrentInfo;
	unsigned char ucTagMode;

	if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
	{
		ucCurrentInfo = ucUSB_DisplayInfo;
		ucTagMode = ucUSB_Display_ID3Tag;
	}
#ifdef  CD
	else
	{
		ucCurrentInfo = ucCD_Display_Info;
		ucTagMode = ucCD_Display_ID3Tag;
	}
#endif
	switch (ucLC786XXX_GetText_Type)
	{
		case LC786X_TEXT_FILE_NAME:
			if	((ucCurrentInfo == INFO_FILENAME) || ((ucDISP_FolderName == 0) && (ucDISP_FileName == 1)))
			{
				DISP_PageScrollReset();
				DISP_ClearTempDisplayMode();
				MENU_Clear();
			}
			break;
		case LC786X_TEXT_FOLDER_NAME:
			if	((ucCurrentInfo == INFO_FOLDERNAME) || (ucDISP_FolderName == 1))
			{
				DISP_PageScrollReset();
				DISP_ClearTempDisplayMode();
				MENU_Clear();
			}
			break;
		case LC786X_TEXT_TITLE:
		case LC786X_TEXT_ARTIST:
		case LC786X_TEXT_ALBUM:
		case LC786X_TEXT_ARTIST_ALBUM:
		case LC786X_TEXT_YEAR:
		case LC786X_TEXT_COMMENT:
		case LC786X_TEXT_GENRE:
			if	(ucCurrentInfo == INFO_ID3TAG)
			{
				DISP_PageScrollReset();
				DISP_ClearTempDisplayMode();
				MENU_Clear();
			}
			break;		
	}

	++ucLC786XXX_GetText_Type;
#ifdef  LC78696X
	if  (ucLC786XXX_GetText_Type > LC786X_TEXT_ARTIST_ALBUM)
#else
	if  (ucLC786XXX_GetText_Type > LC786X_TEXT_ALBUM)
#endif
	{
		DRV_LC786XXX_GetCurrentFileInformation();
		ucLC786XXX_GetText_Seq = LC786XXX_GTEXT_IDLE;
		LOG_TEXT("LC786XXX_GTEXT_FINISH");
	}
	else
	{
		DRV_LC786XXX_GetCurrentMediaTextData(ucLC786XXX_GetText_Type,0x00,0x00,MEDIA_CHAR_SIZE);
		ucLC786XXX_GetText_Seq = LC786XXX_GTEXT_GET_DATA_R;
		LOG_TEXT("LC786XXX_GTEXT_TEXT_SELECT:%d", ucLC786XXX_GetText_Type);
	}
}

void LC786XXX_GetText_SaveFileName(void)
{
	unsigned char *ucTargetBuf;
	unsigned char *ucCharCode;
	
#ifdef  CD
	if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
	{
		ucTargetBuf = &ucCD_FileName[0];
		ucCharCode = &ucCD_FileName_CharCode;
		CD_SetTextStatus(UI_TEXT_READY_FILENAME);
		LOG_TEXT("FileName");
		*ucCharCode = ucLC786XXX_GetText_CharCode;
//		LOG_LC786("CharCode:%X",*ucCharCode);
//		memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
//		memcpy(ucTargetBuf,&ucLC786XXX_TextBuf[0],usLC786XXX_GetText_Length);
		LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
	}
#endif
	if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
	{
		ucTargetBuf = &ucUSB_FileName[0];
		ucCharCode = &ucUSB_FileName_CharCode;
		USB_SetTextStatus(UI_TEXT_READY_FILENAME);
		LOG_TEXT("FileName");
		*ucCharCode = ucLC786XXX_GetText_CharCode;
//		LOG_LC786("CharCode:%X",*ucCharCode);
//		memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
//		memcpy(ucTargetBuf,&ucLC786XXX_TextBuf[0],usLC786XXX_GetText_Length);
		LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
	}
}

void LC786XXX_GetText_SaveFolderName(void)
{
	unsigned char *ucTargetBuf;
	unsigned char *ucCharCode;
#ifdef  CD
	if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
	{
		ucTargetBuf = &ucCD_FolderName[0];
		ucCharCode = &ucCD_FolderName_CharCode;
		CD_SetTextStatus(UI_TEXT_READY_FOLDERNAME);
		LOG_TEXT("FolderName");
		*ucCharCode = ucLC786XXX_GetText_CharCode;
		LOG_TEXT("CharCode:%X",*ucCharCode);
	//	memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
	//	memcpy(ucTargetBuf,&ucLC786XXX_TextBuf[0],usLC786XXX_GetText_Length);
		LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
	}
#endif
	if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
	{
		ucTargetBuf = &ucUSB_FolderName[0];
		ucCharCode = &ucUSB_FolderName_CharCode;
		USB_SetTextStatus(UI_TEXT_READY_FOLDERNAME);
		LOG_TEXT("FolderName");
		*ucCharCode = ucLC786XXX_GetText_CharCode;
		LOG_TEXT("CharCode:%X",*ucCharCode);
	//	memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
	//	memcpy(ucTargetBuf,&ucLC786XXX_TextBuf[0],usLC786XXX_GetText_Length);
		LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
	}
}

void LC786XXX_GetText_SaveText(void)
{
	unsigned char *ucTargetBuf;
	unsigned char *ucCharCode;

	LOG_TEXT("LC786XXX_GTEXT_GET_TEXT_R");
	if  (ucLC786XXX_GetText_Type == LC786X_TEXT_FILE_NAME)
	{
		LC786XXX_GetText_SaveFileName();
	}
	else if  (ucLC786XXX_GetText_Type == LC786X_TEXT_FOLDER_NAME)
	{
		LC786XXX_GetText_SaveFolderName();
	}
	else if  (ucLC786XXX_GetText_Type == LC786X_TEXT_TITLE)
	{
	#ifdef  CD
		if  ((ucLC786XXX_CurrentMediaID == LC786X_CDROM) || (ucLC786XXX_CurrentMediaID == LC786X_CDDA))
		{
			ucTargetBuf = &ucCD_ID3_Title[0];
			ucCharCode = &ucCD_ID3_Title_CharCode;
			CD_SetTextStatus(UI_TEXT_READY_TITLE);
			LOG_TEXT("Title");
			*ucCharCode = ucLC786XXX_GetText_CharCode;
			LOG_TEXT("CharCode:%X",*ucCharCode);
		//	memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		//	memcpy(ucTargetBuf,&ucLC786XXX_TextBuf[0],usLC786XXX_GetText_Length);
			LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
		}
	//	if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
	//	{
	//		ucTargetBuf = &ucCD_ID3_Title[0];
	//		ucCharCode = &ucCD_ID3_Title_CharCode;
	//		CD_SetTextStatus(UI_TEXT_READY_TITLE);
	//		ucLC786XXX_GetText_Seq = LC786XXX_GTEXT_IDLE;// end
	//		LOG_TEXT("CDDA_Text");					
	//	}
	#endif
		if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
		{
			ucTargetBuf = &ucUSB_ID3_Title[0];
			ucCharCode = &ucUSB_ID3_Title_CharCode;
			USB_SetTextStatus(UI_TEXT_READY_TITLE);
			LOG_TEXT("Title");
			*ucCharCode = ucLC786XXX_GetText_CharCode;
			LOG_TEXT("CharCode:%X",*ucCharCode);
		//	memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		//	memcpy(ucTargetBuf,&ucLC786XXX_TextBuf[0],usLC786XXX_GetText_Length);
			LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
		}
	}
	else if  (ucLC786XXX_GetText_Type == LC786X_TEXT_ARTIST)
	{
	#ifdef  CD
		if  ((ucLC786XXX_CurrentMediaID == LC786X_CDROM) || (ucLC786XXX_CurrentMediaID == LC786X_CDDA))
		{
			ucTargetBuf = &ucCD_ID3_Artist[0];
			ucCharCode = &ucCD_ID3_Artist_CharCode;
			CD_SetTextStatus(UI_TEXT_READY_ARTIST);
			LOG_TEXT("Artist");
			*ucCharCode = ucLC786XXX_GetText_CharCode;
			LOG_TEXT("CharCode:%X",*ucCharCode);
		//	memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		//	memcpy(ucTargetBuf,&ucLC786XXX_TextBuf[0],usLC786XXX_GetText_Length);
			LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
		}
	#endif
		if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
		{
			ucTargetBuf = &ucUSB_ID3_Artist[0];
			ucCharCode = &ucUSB_ID3_Artist_CharCode;
			USB_SetTextStatus(UI_TEXT_READY_ARTIST);
			LOG_TEXT("Artist");
			*ucCharCode = ucLC786XXX_GetText_CharCode;
			LOG_TEXT("CharCode:%X",*ucCharCode);
		//	memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		//	memcpy(ucTargetBuf,&ucLC786XXX_TextBuf[0],usLC786XXX_GetText_Length);
			LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
		}
	}
	else if  (ucLC786XXX_GetText_Type == LC786X_TEXT_ALBUM)
	{
	#ifdef  CD
		if  ((ucLC786XXX_CurrentMediaID == LC786X_CDROM) || (ucLC786XXX_CurrentMediaID == LC786X_CDDA))
		{
			ucTargetBuf = &ucCD_ID3_Album[0];
			ucCharCode = &ucCD_ID3_Album_CharCode;
			CD_SetTextStatus(UI_TEXT_READY_ALBUM);
			LOG_TEXT("Album");
			*ucCharCode = ucLC786XXX_GetText_CharCode;
			LOG_TEXT("CharCode:%X",*ucCharCode);
		//	memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		//	memcpy(ucTargetBuf,&ucLC786XXX_TextBuf[0],usLC786XXX_GetText_Length);
			LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
		}
	#endif
		if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
		{
			ucTargetBuf = &ucUSB_ID3_Album[0];
			ucCharCode = &ucUSB_ID3_Album_CharCode;
			USB_SetTextStatus(UI_TEXT_READY_ALBUM);
			LOG_TEXT("Album");
			*ucCharCode = ucLC786XXX_GetText_CharCode;
			LOG_TEXT("CharCode:%X",*ucCharCode);
		//	memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		//	memcpy(ucTargetBuf,&ucLC786XXX_TextBuf[0],usLC786XXX_GetText_Length);
			LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
		}
	}
	else  if  (ucLC786XXX_GetText_Type == LC786X_TEXT_ARTIST_ALBUM)
	{
	#ifdef  CD
		if  ((ucLC786XXX_CurrentMediaID == LC786X_CDROM) || (ucLC786XXX_CurrentMediaID == LC786X_CDDA))
		{
			ucTargetBuf = &ucCD_ID3_AlbumArtist[0];
			ucCharCode = &ucCD_ID3_AlbumArtist_CharCode;
			CD_SetTextStatus(UI_TEXT_READY_ALBUMARTIST);
			*ucCharCode = ucLC786XXX_GetText_CharCode;
			LOG_TEXT("CharCode:%X",*ucCharCode);
			LC786XXX_GetText_CopyText(*ucCharCode, &ucLC786XXX_TextBuf[0], ucTargetBuf, usLC786XXX_GetText_Length);
			LOG_TEXT("AlbumArtist");
		}
	#endif
	}
	else  if  (ucLC786XXX_GetText_Type == LC786X_TEXT_YEAR)
	{
	}
	else  if  (ucLC786XXX_GetText_Type == LC786X_TEXT_COMMENT)
	{
	}
	else  if  (ucLC786XXX_GetText_Type == LC786X_TEXT_GENRE)
	{
	}
	
	LC786XXX_GetText_SelectNext();
}

void LC786XXX_GetText_ClearText(void)
{
	unsigned char *ucTargetBuf;
	unsigned char *ucCharCode;

	LOG_TEXT("LC786XXX_GetText_ClearText");
	if  (ucLC786XXX_GetText_Type == LC786X_TEXT_FILE_NAME)
	{
	#ifdef  CD
		if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
		{
			ucTargetBuf = &ucCD_FileName[0];
			CD_ClearTextStatus(UI_TEXT_READY_FILENAME);
			LOG_TEXT("FileName");
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		}
	#endif
		if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
		{
			ucTargetBuf = &ucUSB_FileName[0];
			USB_ClearTextStatus(UI_TEXT_READY_FILENAME);
			LOG_TEXT("FileName");
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		}
	}
	else if  (ucLC786XXX_GetText_Type == LC786X_TEXT_FOLDER_NAME)
	{
	#ifdef  CD
		if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
		{
			ucTargetBuf = &ucCD_FolderName[0];
			CD_ClearTextStatus(UI_TEXT_READY_FOLDERNAME);
			LOG_TEXT("FolderName");
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		}
	#endif
		if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
		{
			ucTargetBuf = &ucUSB_FolderName[0];
			USB_ClearTextStatus(UI_TEXT_READY_FOLDERNAME);
			LOG_TEXT("FolderName");
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		}
	}
	else if  (ucLC786XXX_GetText_Type == LC786X_TEXT_TITLE)
	{
	#ifdef  CD
		if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
		{
			ucTargetBuf = &ucCD_ID3_Title[0];
			CD_ClearTextStatus(UI_TEXT_READY_TITLE);
			LOG_TEXT("Title");
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		}
		if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
		{
			ucTargetBuf = &ucCD_ID3_Title[0];
			CD_ClearTextStatus(UI_TEXT_READY_TITLE);
			ucLC786XXX_GetText_Seq = LC786XXX_GTEXT_IDLE;// end
			LOG_TEXT("CDDA_Text");	
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);				
		}
	#endif
		if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
		{
			ucTargetBuf = &ucUSB_ID3_Title[0];
			USB_ClearTextStatus(UI_TEXT_READY_TITLE);
			LOG_TEXT("Title");
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		}
	}
	else if  (ucLC786XXX_GetText_Type == LC786X_TEXT_ARTIST)
	{
	#ifdef  CD
		if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
		{
			ucTargetBuf = &ucCD_ID3_Artist[0];
			CD_ClearTextStatus(UI_TEXT_READY_ARTIST);
			LOG_TEXT("Artist");
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		}
	#endif
		if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
		{
			ucTargetBuf = &ucUSB_ID3_Artist[0];
			USB_ClearTextStatus(UI_TEXT_READY_ARTIST);
			LOG_TEXT("Artist");
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		}
	}
	else if  (ucLC786XXX_GetText_Type == LC786X_TEXT_ALBUM)
	{
	#ifdef  CD
		if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
		{
			ucTargetBuf = &ucCD_ID3_Album[0];
			CD_ClearTextStatus(UI_TEXT_READY_ALBUM);
			LOG_TEXT("Album");
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		}
	#endif
		if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
		{
			ucTargetBuf = &ucUSB_ID3_Album[0];
			USB_ClearTextStatus(UI_TEXT_READY_ALBUM);
			LOG_TEXT("Album");
			LOG_TEXT("CharCode:%X",*ucCharCode);
			memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
		}
	}
	else  if  (ucLC786XXX_GetText_Type == LC786X_TEXT_ARTIST_ALBUM)
	{
	#ifdef  CD
		ucTargetBuf = &ucCD_ID3_AlbumArtist[0];
		CD_ClearTextStatus(UI_TEXT_READY_ALBUMARTIST);
		LOG_TEXT("AlbumArtist");
		memset(ucTargetBuf, 0x00, MEDIA_CHAR_SIZE);
	#endif
	}
	else  if  (ucLC786XXX_GetText_Type == LC786X_TEXT_YEAR)
	{
	}
	else  if  (ucLC786XXX_GetText_Type == LC786X_TEXT_COMMENT)
	{
	}
	else  if  (ucLC786XXX_GetText_Type == LC786X_TEXT_GENRE)
	{
	}
}


void LC786XXX_GetText_Process(UI_FUNCTION ucFunc)
{
	unsigned char i;
	
	if  ((ucLC786XXX_FileStatus & 0x80) == 0x80)
	{
		LOG_TEXT("LC786XXX_FileInfoRead_Process:OnGoing");
		ucLC786XXX_MediaStatusCheck_10msecTimer = 0;
		return;
	}

#if  1
	switch  (ucLC786XXX_GetText_Seq)
	{
		case LC786XXX_GTEXT_IDLE:
		#ifdef  FILE_SEARCH
			LC786XXX_GetFileName();
		#endif
			break;
		case LC786XXX_GTEXT_TEXT_START:
			memset(&ucLC786XXX_TextBuf[0], 0x00, MEDIA_CHAR_SIZE);
			ucLC786XXX_GetText_Type = LC786X_TEXT_FILE_NAME;
			ucLC786XXX_GetText_Seq = LC786XXX_GTEXT_GET_DATA_R;
			DRV_LC786XXX_GetCurrentMediaTextData(ucLC786XXX_GetText_Type,0x00,0x00,MEDIA_CHAR_SIZE);
			break;
		case LC786XXX_GTEXT_GET_DATA_R:
			if  (ucLC786XXX_GetText_Status == 0x00)
			{
				LC786XXX_GetText_ClearText();
				LC786XXX_GetText_SelectNext();
				LOG_TEXT("LC786XXX_GTEXT_GET_SIZE_R:Absent");
			}
			else if  (ucLC786XXX_GetText_Status == 0x02)
			{
				LOG_TEXT("LC786XXX_GTEXT_GET_SIZE_R:OK");
			}
			else
			{
				DRV_LC786XXX_GetCurrentMediaTextData(ucLC786XXX_GetText_Type,0x00,0x00,MEDIA_CHAR_SIZE);
				LOG_TEXT("LC786XXX_GTEXT_GET_SIZE_R:Ongoing");
			}
			break;
	}
#else
	
	switch  (ucLC786XXX_GetText_Seq)
	{
		case LC786XXX_GTEXT_IDLE:
			break;
		case LC786XXX_GTEXT_TEXT_START:
			memset(&ucLC786XXX_TextBuf[0], 0x00, MEDIA_CHAR_SIZE);
			ucLC786XXX_GetText_Seq = LC786XXX_GTEXT_GET_DATA;
			LOG_TEXT("LC786XXX_GTEXT_TEXT_START");
		case LC786XXX_GTEXT_GET_DATA:
		#ifdef  LC78696X
		//	if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
		//	{				
		//		DRV_LC786XXX_GetCDTextData(0x00,ulLC786XXX_PlaySerialNo,ucLC786XXX_TextInfoRead_Mode_BlockNo,0x00,0x00);
		//	}
		//	else
		#endif
			{
				DRV_LC786XXX_GetCurrentMediaTextData(ucLC786XXX_GetText_Type,0x00,0x00,MEDIA_CHAR_SIZE);
			}
			LOG_TEXT("LC786XXX_GTEXT_GET_SIZE");
			ucLC786XXX_GetText_Seq = LC786XXX_GTEXT_GET_DATA_R;
			break;
		case LC786XXX_GTEXT_GET_DATA_R:
			if  (ucLC786XXX_GetText_Status == 0x02)
			{
				LOG_TEXT("LC786XXX_GTEXT_GET_SIZE_R:OK");
				DRV_LC786XXX_GetCurrentMediaTextData(ucLC786XXX_GetText_Type,0x00,0x00,MEDIA_CHAR_SIZE);
			}
			else  if  (ucLC786XXX_GetText_Status == 0x00)
			{
				LC786XXX_GetText_ClearText();
				LC786XXX_GetText_SelectNext();
				LOG_TEXT("LC786XXX_GTEXT_GET_SIZE_R:Absent");
			}
			else
			{
			#ifdef  LC78696X
			//	if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
			//	{
			//		DRV_LC786XXX_GetCDTextData(0x00,ulLC786XXX_PlaySerialNo,ucLC786XXX_TextInfoRead_Mode_BlockNo,0x00,0x00);
			//	}
			//	else
			#endif
				{
			//		DRV_LC786XXX_GetCurrentMediaTextData(ucLC786XXX_GetText_Type,0x00,0x00,0x00);
					DRV_LC786XXX_GetCurrentMediaTextData(ucLC786XXX_GetText_Type,0x00,0x00,MEDIA_CHAR_SIZE);
				}
				LOG_TEXT("LC786XXX_GTEXT_GET_SIZE_R:OnGoing");
			}
			break;
		case LC786XXX_GTEXT_GET_NEXT:		
			DRV_LC786XXX_GetCurrentMediaTextData(ucLC786XXX_GetText_Type,0x00,0x00,MEDIA_CHAR_SIZE);
			ucLC786XXX_GetText_Seq = LC786XXX_GTEXT_GET_DATA_R;
			break;
	}
#endif
}

#ifdef  LC78696X

void LC786XXX_ChangeToCD(void)
{
	ucLC786XXX_USB_PlayOrder = DRV_LC786XXX_GetPlayOrder();
	
	ucLC786XXX_USB_Process = LC786XXX_PROCESS_IDLE;
	ucLC786XXX_CD_Process = LC786XXX_PROCESS_MEDIA_CHANGE;
	ucLC786XXX_Process_10msecTimer = 100/10;
	ucLC786XXX_MediaStatusCheck_10msecTimer = 0;
	#ifdef  LC78696X
	if  (LC786XXX_WakeUp() == 1)
	{
		ucLC786XXX_Process_10msecTimer = 500/10;
	}
	#endif
}

unsigned char LC786XXX_CD_ResumeMount;

void LC786XXX_CDFunctionProcess(void)
{	
	switch  (ucLC786XXX_CD_Process)
	{
		case LC786XXX_PROCESS_CHECK_MOUNTED:
			LC786XXX_CD_ResumeMount = 0;
			if  (ucCD_Status == CD_STATUS_MOUNTED)
			{
				LOG_LC786("LC786XXX_PROCESS_CHECK_MOUNTED:RESUME:CD");
				ucLC786XXX_CD_Process = LC786XXX_PROCESS_PLAY_REQUEST;
			}
			else
			{
				LOG_LC786("LC786XXX_PROCESS_CHECK_MOUNTED:READING:CD");
				ucCD_CurrentPlayDiscType = CD_DISC_CDDA;	
				ucLC786XXX_CD_PlayOrder = 0x40;			
				DRV_LC786XXX_SetPlayOrder(ucLC786XXX_CD_PlayOrder);
				DRV_LC786XXX_Playback(ucLC786XXX_CurrentMediaID, 0x02);	// Reading...
				ucLC786XXX_CD_Process = LC786XXX_PROCESS_WAIT_READING;
				ucCD_Status = CD_STATUS_READING;
				if  (ucCD_Resume == 1)
				{
					LC786XXX_CD_ResumeMount = 1;
				}
			}			
			break;
		case LC786XXX_PROCESS_WAIT_READING:	// Wait to Reading
			if  (
				(ucLC786XXX_CDDA_Status == LC786X_MS_PAUSE_AT_STARTUP) || (ucLC786XXX_CDROM_Status == LC786X_MS_PAUSE_AT_STARTUP)
				|| (ucLC786XXX_CDDA_Status == LC786X_MS_PAUSE) || (ucLC786XXX_CDROM_Status == LC786X_MS_PAUSE)
				|| (ucLC786XXX_CDDA_Status == LC786X_MS_PAUSE_AT_HEADER_OF_DISC) || (ucLC786XXX_CDROM_Status == LC786X_MS_PAUSE_AT_HEADER_OF_DISC)
				|| (ucLC786XXX_CDDA_Status == LC786X_MS_STOP) || (ucLC786XXX_CDROM_Status == LC786X_MS_STOP)
				)
			{
				LOG_LC786("LC786XXX_PROCESS_WAIT_READING:CD");
				DRV_LC786XXX_Get_DiscType();
		//		if  (LC786XXX_CD_ResumeMount == 1)
		//		{					
		//			DRV_LC786XXX_Stop(ucLC786XXX_CurrentMediaID, 0x00);
		//		}
				ucLC786XXX_CD_Process = LC786XXX_PROCESS_GET_TOTALFILE;
			}
			DRV_LC786XXX_GetCurrentMediaStatus(0x00);
			break;
		case LC786XXX_PROCESS_GET_TOTALFILE:	// Get CD Type
			LOG_LC786("LC786XXX_PROCESS_GET_TOTALFILE:CD");
			DRV_LC786XXX_Get_CDToc(0x00);
			if  ((ucLC78696X_DiscType == LC786X_DISC_CDROM) || (ucLC78696X_DiscType == LC786X_DISC_MIXED))
			{
				DRV_LC786XXX_GetTotalMediaFile(LC786X_CDROM,0x00,0x00);
				ucLC786XXX_CD_Process = LC786XXX_PROCESS_PLAY_REQUEST;
			}
			else  if  (ucLC78696X_DiscType == LC786X_DISC_CDDA)
			{
				ucLC786XXX_CD_Process = LC786XXX_PROCESS_PLAY_REQUEST;
			}
			else
			{
				// Error
				ucLC786XXX_CD_Process = LC786XXX_PROCESS_NORMAL;
			}
			break;
		case LC786XXX_PROCESS_PLAY_REQUEST:	// Get Total File and play
			LOG_LC786("LC786XXX_PROCESS_PLAY_REQUEST:CD");
			LOG_LC786("DiscType:%d",ucLC78696X_DiscType);
			LOG_LC786("TotalFile:%d",usLC786XXX_CDROM_TotalFile);
			if  (ucLC78696X_DiscType == LC786X_DISC_CDDA)
			{
				if  (ucCD_Resume == 1)
				{
					if  (LC786XXX_CD_ResumeMount == 1)
					{
						UI_PLAY_INFO	sPlayInfo;

						sPlayInfo.FolderNo = 0;
						sPlayInfo.FileNo = 0;
						sPlayInfo.Hour = 0;
						sPlayInfo.Min = ucLC786XXX_CDDA_AbsoluteTimeMin;
						sPlayInfo.Sec = ucLC786XXX_CDDA_AbsoluteTimeSec;
						DRV_LC78696X_PlayCDTrack_AbsoluteTime(sPlayInfo);
						LC786XXX_CD_ResumeMount = 0;
					}
					else
					{
						DRV_LC786XXX_Playback(LC786X_CDDA, 0x01);
					}
					LOG_LC786("1");
				}
				else
				{
					DRV_LC786XXX_Playback(LC786X_CDDA, 0x00);
					LOG_LC786("2");
				}
				ucCD_CurrentPlayDiscType = CD_DISC_CDDA;
			}
			else  if  (ucLC78696X_DiscType == LC786X_DISC_CDROM)
			{				
				if  (usLC786XXX_CDROM_TotalFile == 0)
				{
					ucCD_Status = CD_STATUS_NOFILE;
				}
				else
				{
					if  (ucCD_Resume == 1)
					{
						DRV_LC786XXX_PlayFileNumber(LC786X_CDROM, sCD_PlayInfo);
						LOG_LC786("3");
					}
					else
					{
						DRV_LC786XXX_Playback(LC786X_CDROM, 0x00);
						LOG_LC786("4");
					}
					ucCD_CurrentPlayDiscType = CD_DISC_CDROM;
				}
			}
			else  if  (ucLC78696X_DiscType == LC786X_DISC_MIXED)
			{
				if  (ucCD_CurrentPlayDiscType == CD_DISC_CDROM)
				{
					if  (ucCD_Resume == 1)
					{
						DRV_LC786XXX_PlayFileNumber(LC786X_CDROM, sCD_PlayInfo);
						LOG_LC786("5");
					}
					else
					{
						DRV_LC786XXX_Playback(LC786X_CDROM, 0x00);
						LOG_LC786("6");
					}
					ucCD_CurrentPlayDiscType = CD_DISC_CDROM;
				}
				else
				{
					if  (ucCD_Resume == 1)
					{
						if  (LC786XXX_CD_ResumeMount == 1)
						{
							UI_PLAY_INFO	sPlayInfo;

							sPlayInfo.FolderNo = 0;
							sPlayInfo.FileNo = 0;
							sPlayInfo.Hour = 0;
							sPlayInfo.Min = ucLC786XXX_CDDA_AbsoluteTimeMin;
							sPlayInfo.Sec = ucLC786XXX_CDDA_AbsoluteTimeSec;
							DRV_LC78696X_PlayCDTrack_AbsoluteTime(sPlayInfo);
							LC786XXX_CD_ResumeMount = 0;
						}
						else
						{
							DRV_LC786XXX_Playback(LC786X_CDDA, 0x01);
						}
						LOG_LC786("7");
					}
					else
					{
						DRV_LC786XXX_Playback(LC786X_CDDA, 0x00);
						LOG_LC786("8");
					}
					ucCD_CurrentPlayDiscType = CD_DISC_CDDA;
				}
			}
			if  (ucCD_Repeat == REPEAT_FILE)
			{
				DRV_LC786XXX_Set_Repeat(LC786X_RPT_FILE);
			}
			if  (ucCD_Repeat == REPEAT_FOLDER)
			{
				DRV_LC786XXX_Set_Repeat(LC786X_RPT_FLD);
			}
			ucLC786XXX_CD_Process = LC786XXX_PROCESS_CHECK_PLAY;
			break;
		case LC786XXX_PROCESS_CHECK_PLAY:
			if  ((LC786XXX_GetMediaStatus(FUNC_CD) == LC786X_MS_PLAYBACK)
				|| (LC786XXX_GetMediaStatus(FUNC_CD) == LC786X_MS_PLAYBACK_PLAYLIST))
			{
				ucLC786XXX_CD_Process = LC786XXX_PROCESS_NORMAL;
				ucCD_Status = CD_STATUS_MOUNTED;
			}
			break;
		case LC786XXX_PROCESS_EJECT:
			if  ((ucLC786XXX_CurrentMediaID == LC786X_CDDA) || (ucLC786XXX_CurrentMediaID == LC786X_CDROM))
			{
				if  ((LC786XXX_GetMediaStatus(FUNC_CD) > LC786X_MS_STOP) &&
					(LC786XXX_GetMediaStatus(FUNC_CD) < LC786X_MS_OPERATION_NOT_BOOTED_YET_USB))
				{
					DRV_LC786XXX_Stop(ucLC786XXX_CurrentMediaID, 0x01);
				}
			}
			ucLC786XXX_CD_Process = LC786XXX_PROCESS_EJECT_WAIT_STOP;
			ucLC786XXX_MediaStatusCheck_10msecTimer = 0;
			break;
		case LC786XXX_PROCESS_EJECT_WAIT_STOP:
			if  ((ucLC786XXX_CDDA_Status == LC786X_MS_STOP)
				|| (ucLC786XXX_CDDA_Status == LC786X_MS_STOP_NO_TOC)
				|| (ucLC786XXX_CDDA_Status == 0x81))
			{
				ucLC786XXX_CD_Process = LC786XXX_PROCESS_IDLE;
				DRV_LC786XXX_ClearInfomation(0x02);
			}
			break;
		case LC786XXX_PROCESS_MEDIA_CHANGE:
		#if  1
			if  (((ucLC786XXX_CurrentMediaID == LC786X_CDDA)) || (ucLC786XXX_CurrentMediaID == LC786X_CDROM))
			{
				ucLC786XXX_CD_Process = LC786XXX_PROCESS_CHECK_MOUNTED;
			}
			else
			{
				if  (ucLC786XXX_Process_10msecTimer == 0)
				{
					if  (ucCD_CurrentPlayDiscType == CD_DISC_CDROM)
					{
						DRV_LC786XXX_MediaSelect(LC786X_CDROM);
					}
					else
					{
						DRV_LC786XXX_MediaSelect(LC786X_CDDA);
					}
					ucLC786XXX_Process_10msecTimer = 1000/10;
				}
			}
		#else
			if  (ucLC786XXX_Process_10msecTimer == 0)
			{
				if  (ucCD_CurrentPlayDiscType == CD_DISC_CDROM)
				{
					DRV_LC786XXX_MediaSelect(LC786X_CDROM);
				}
				else
				{
					DRV_LC786XXX_MediaSelect(LC786X_CDDA);
				}
				ucLC786XXX_Process_10msecTimer = 200/10;
			}
			else
			{
			#if  1
				if  (((ucLC786XXX_CurrentMediaID == LC786X_CDDA)) || (ucLC786XXX_CurrentMediaID == LC786X_CDROM))
				{
					ucLC786XXX_CD_Process = LC786XXX_PROCESS_CHECK_MOUNTED;	
				}
			#else
				if  (ucCD_CurrentPlayDiscType == CD_DISC_CDROM)
				{
					if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
					{
						ucLC786XXX_CD_Process = LC786XXX_PROCESS_CHECK_MOUNTED;	
					}	
				}
				else
				{
					if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
					{
						ucLC786XXX_CD_Process = LC786XXX_PROCESS_CHECK_MOUNTED;	
					}
				}
			#endif
			}
		#endif
			break;
	}
}

#endif	// CD

void LC786XXX_USB_DetectMain(void)	// 20 msec
{
///////// Pre check USB Detect port /////////////////
	if  (ucLC786XXX_USB_DetectPort == PI_USB_DET)
	{
		if  (ucLC786XXX_USB_Detect_Timer10msec == 0)
		{
			if  (ucLC786XXX_USB_DetectPort == 1)
			{
				if  (ucAUDIO_TelMute == 1)
				{
					return;
				}
			#ifdef  AUTO_GUIDE
				if  (AG_GetAnnounceStatus() == AG_ANNOUNCE_ON)
				{
					return;
				}
			#endif
				if  (ucLC786XXX_USB_Status == LC786X_MS_MASS_STORAGE_CONNECT)
				{
				#ifdef  BLUETOOTH
					if  (FUNC_GetCurrentFunction() != FUNC_HF)
				#endif
					{
						if  ((usLC786XXX_InitUSB_10mecTimer == 0) && (ucLC786XXX_USB_Detected == 0))
						{
							DISP_ClearTempDisplayMode();
							MENU_Clear();
						#ifdef  MIC
							if  (MIC_GetHostMicStatus() == MIC_ON)
							{
								MIC_SetHostMicStatus(MIC_OFF);
							}
						#endif							
							FUNC_FunctionChangeStart(FUNC_USB, FUNC_CHANGE_SEQ0);
						}
					}
					ucLC786XXX_USB_Detected = 1;
					usLC786XXX_InitUSB_10mecTimer = 0;
				}
			}
			else
			{
				if  (usLC786XXX_InitUSB_10mecTimer == 0)
				{
					if  (ucLC786XXX_USB_Detected == 1)
					{
						if  ((FUNC_GetCurrentFunction() == FUNC_USB) && (ucFUNC_Power == 1))
						{
						#ifdef  MIC
							if  (MIC_GetHostMicStatus() == MIC_ON)
							{
								MIC_SetHostMicStatus(MIC_OFF);
							}
						#endif
							DISP_ClearTempDisplayMode();
							MENU_Clear();
							FUNC_FunctionChangeStart(FUNC_GetPreviousFunction(), FUNC_CHANGE_SEQ0);
						}
						USB_Variable_Initalize();
						ucLC786XXX_USB_Process = LC786XXX_PROCESS_IDLE;
					}
					ucLC786XXX_USB_Detected = 0;
				}
			}
		}
		else
		{
		}
	}
	else
	{
		ucLC786XXX_USB_Detect_Timer10msec = 100/10;
		ucLC786XXX_USB_DetectPort = PI_USB_DET;
	}
}

void LC786XXX_MediaStop(UI_FUNCTION ucFunc)
{
	#ifdef  CD
	if  (ucFunc == FUNC_CD)
	{
//		CD_ClearStatusFlag(UI__PLAY);
		if  (ucDECK_Mode == DECK_MODE_EJECT)
		{
	//		ucLC786XXX_CD_Process = LC786XXX_PROCESS_EJECT;
		}
		else
		{
			if  ((ucLC786XXX_CurrentMediaID == LC786X_CDDA) || (ucLC786XXX_CurrentMediaID == LC786X_CDROM))
			{
				DRV_LC786XXX_Stop(ucLC786XXX_CurrentMediaID, 0x00);
			}
			ucLC786XXX_CD_Process = LC786XXX_PROCESS_IDLE;
		}
	}
	#endif
	if  (ucFunc == FUNC_USB)
	{
		if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
		{
			DRV_LC786XXX_Stop(LC786X_USB, 0x00);
		}
		ucLC786XXX_USB_Process = LC786XXX_PROCESS_IDLE;
	}
}

unsigned char LC786XXX_PreviousCondition(void)
{
	if  ((ucLC786XXX_PlayHour == 0) && (ucLC786XXX_PlayMin == 0) && (ucLC786XXX_PlaySec < 6))
	{
		return(0);
	}
	return(1);
}

unsigned char LC786XXX_SkipFile(unsigned char ucDir)
{	
	unsigned char ucMode;
	unsigned char ucDes = 1;
	
	if  (ucDir == 0x00)	// Previous
	{
		if  (LC786XXX_PreviousCondition() == 0)
		{
			ucMode = 0x01;
		}
		else
		{
			ucMode = 0x02;
			ucDes = 0;
		}
	}
	else	// Next
	{
		ucMode = 0x00;
	}
	DRV_LC786XXX_Skip_SkipFolder(ucMode);

	return(ucDes);
}

void LC786XXX_MoveToStartOfTrack(void)
{
	DRV_LC786XXX_Skip_SkipFolder(0x02);
}

void LC786XXX_SkipFolder(unsigned char ucDir)
{
	unsigned char ucMode;

	if  (ucDir == 0x00)
	{
		DRV_LC786XXX_Skip_SkipFolder(0x81);
	}
	else
	{
		DRV_LC786XXX_Skip_SkipFolder(0x80);
	}
}

void LC786XXX_FastPlayback(unsigned char ucDir)
{
	if  (ucDir == 0x03)	// Release
	{
		DRV_LC786XXX_Playback(LC786X_CURRENT, 0x01);	// Resume Play
	}
	else
	{
		DRV_LC786XXX_FastForward_FastBack(ucDir);
	}
}

unsigned char ucLC786XXX_ErrorSeq;
unsigned char ucLC786XXX_ErrorSeq_100msec;

void LC786XXX_ErrorCodeProcess(LC786X_MEDIA_ID ucMediaID)
{
	switch  (LC786XXX_GetErrorCode(ucMediaID))
	{
		case LC786X_EC_NoError:
			if  (ucMediaID == LC786X_USB)
			{
				ucUSB_ErrorCode = LC786X_EC_NoError;
			}
			break;
		case LC786X_EC_FlashError: 					//0Fh     
		case LC786X_EC_DSP_CommunicationError: 		//32h
		case LC786X_EC_AudioDecoderInitializeError: //34h 
		case LC786X_EC_SDRAM_Error: 				//35h
		case LC786X_EC_USB_ErrUnexpected: 			//60h 
		case LC786X_EC_FileSysInitializeError: 		//68h 
			USB_Variable_Initalize();
			#ifdef CD
			CD_Variable_Initalize();
			ucCD_Status = CD_STATUS_LOADED;
			#endif
			LC786XXX_StartInitialize();
			AUDIO_MuteOn();
			FUNC_FunctionChangeStart(FUNC_GetPreviousFunction(), FUNC_POWER_ON_SEQ0);
			ucLC786XXX_CDDA_ErrorCode = 0;
			ucLC786XXX_CDROM_ErrorCode = 0;
			ucLC786XXX_USB_ErrorCode = 0;
			break;				//16h
		case LC786X_EC_MirrorDetect: 		//11h
		case LC786X_EC_FocusError: 			//12h
		case LC786X_EC_FileAnalyzeError: 	//13h
		case LC786X_EC_NoFile: 				//14h 
		case LC786X_EC_PVD_SVD_ReadError: 	//15h
		case LC786X_EC_No_PVD_SVD: 	
		case LC786X_EC_TrackingError: 		//19h
		case LC786X_EC_AutoAdjustError: 	//20h
		case LC786X_EC_SearchError: 		//21h
		case LC786X_EC_TOC_ReadError: 		//22h
		case LC786X_EC_SubCodeReadError:	//24h
		case LC786X_EC_PUIN_SW_ON_Error: 	//31h
		case LC786X_EC_PUIN_SW_OFF_Error: 	//33h
		case LC786X_EC_USB_ErrDriver: 		//61h  
		case LC786X_EC_USB_EnumerateError: 	//62h 
		case LC786X_EC_USB_ErrResponse: 	//63h
		case LC786X_EC_FileSysUnknown: 		//69h
		case LC786X_EC_FileSysAnalyze: 		//6Ah
	#if  0
			if  (LC786XXX_GetErrorCode(LC786X_USB) != LC786X_EC_NoError)
			{
				ucUSB_ErrorCode = LC786XXX_GetErrorCode(LC786X_USB);
				if  (FUNC_GetCurrentFunction() != FUNC_USB)
				{
					return;
				}
			}
		#ifdef  CD
			if  (LC786XXX_GetErrorCode(LC786X_CDDA) != LC786X_EC_NoError)
			{
				ucCD_ErrorCode = LC786XXX_GetErrorCode(LC786X_CDDA);
				if  (FUNC_GetCurrentFunction() != FUNC_CD)
				{
					return;
				}
			}
			if  (LC786XXX_GetErrorCode(LC786X_CDROM) != LC786X_EC_NoError)
			{
				ucCD_ErrorCode = LC786XXX_GetErrorCode(LC786X_CDROM);
				if  (FUNC_GetCurrentFunction() != FUNC_CD)
				{
					return;
				}
			}
		#endif
	#else
			if  (ucMediaID == LC786X_USB)
			{
				USB_SetStatus(USB_ST_ERROR);
				ucUSB_ErrorCode = LC786XXX_GetErrorCode(ucMediaID);

				if  (FUNC_GetCurrentFunction() != FUNC_USB)
				{
					return;
				}
			}
		#ifdef  CD
			if  ((ucMediaID == LC786X_CDDA) || (ucMediaID == LC786X_CDROM))
			{
				ucCD_Status = CD_STATUS_ERROR;
				ucCD_ErrorCode = LC786XXX_GetErrorCode(ucMediaID);
				
				if  (FUNC_GetCurrentFunction() != FUNC_CD)
				{
					return;
				}
			}
		#endif
	#endif
			FUNC_FunctionChangeStart(FUNC_GetPreviousFunction(), FUNC_CHANGE_SEQ0);
			break;
		case LC786X_EC_DecodeError: 			//41h
		case LC786X_EC_MP3_FileFrameReadError: 	//44h
		case LC786X_EC_MP3_FileFrameError: 		//45h 
		case LC786X_EC_MP3_FileSizeError: 		//46h	
		case LC786X_EC_WMA_FileSizeError: 		//47h 
		case LC786X_EC_WMA_DecodeError: 		//48h
		case LC786X_EC_AAC_FileSizeError: 		//49h 
		case LC786X_EC_AAC_DecodeError: 		//4Ah 
		case LC786X_EC_WMA_CopyrightedFile: 	//51h
		case LC786X_EC_AAC_CopyrightedFile: 	//52h 
		case LC786X_EC_FileOpenError: 			//6Bh	
		case LC786X_EC_FileReadError: 			//6Ch	 
			LC786XXX_SkipFile(1);
			break;			
	}
}

unsigned char LC786XXX_ErrorCodeCheck(LC786X_MEDIA_ID  ucMediaID)
{
	unsigned char ucRet = 1;
	switch  (ucLC786XXX_ErrorSeq)
	{
		case 0:
			if  (LC786XXX_GetErrorCode(ucMediaID) == LC786X_EC_NoError)
			{
				ucRet = 0;
			}
			else
			{
				ucLC786XXX_ErrorSeq = 1;
				ucLC786XXX_ErrorSeq_100msec = 5000/100;
			}
			break;
		case 1:
			if  (ucLC786XXX_ErrorSeq_100msec == 0)
			{
				ucLC786XXX_ErrorSeq = 2;
			}
			break;
		case 2:
			LC786XXX_ErrorCodeProcess(ucMediaID);
			ucLC786XXX_ErrorSeq = 3;
			break;
		case 3:
			if  (LC786XXX_GetErrorCode(ucMediaID) == LC786X_EC_NoError)
			{
				ucRet = 0;
				ucLC786XXX_ErrorSeq = 0;
			}
			break;
	}

	return(ucRet);
}

void LC786XXX_RandomStatusCheck_USB(void)
{
	LC786X_MEDIA_STATUS Status;

	if  (ucUSB_Random == RANDOM_NONE)
	{
		return;
	}

	if  (ucLC786XXX_FileChangeRequest == 1)
	{
		return;
	}
	
	Status = LC786XXX_GetMediaStatus(FUNC_USB);

	switch  (Status)
	{
		case LC786X_MS_PLAYBACK:
		case LC786X_MS_SEARCH:
		case LC786X_MS_PAUSE:
		case LC786X_MS_FASTFORWARD:
		case LC786X_MS_FASTBACK:
			//
			break;
		case LC786X_MS_PAUSE_AT_END_OF_TRACK:
		case LC786X_MS_PAUSE_AT_END_OF_FOLDER:
		case LC786X_MS_PAUSE_AT_END_OF_DISC:
			if  (USB_GetFastPlayStatus() == MEDIA_NORMAL_PLAY)
			{
				USB_RandomFileChange(1);
				ucLC786XXX_FileChangeRequest = 1;
			}
			break;
		case LC786X_MS_PAUSE_AT_HEADER_OF_TRACK:
			if  (USB_GetFastPlayStatus() == MEDIA_NORMAL_PLAY)
			{
				USB_RandomFileChange(1);
				ucLC786XXX_FileChangeRequest = 1;
			}
			break;
		case LC786X_MS_PAUSE_AT_HEADER_OF_FOLDER:
			if  (USB_GetFastPlayStatus() == MEDIA_NORMAL_PLAY)
			{
				USB_RandomFileChange(1);
				ucLC786XXX_FileChangeRequest = 1;
			}
		//case LC786X_MS_PAUSE_AT_HEADER_OF_DISC:
		//	if  (USB_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
		//	{
		//		USB_FFREW_Release();
		//	}
		//	else  
		//	if  (USB_GetFastPlayStatus() == MEDIA_NORMAL_PLAY)
		//	{
		//		USB_RandomFileChange(1);
		//		ucLC786XXX_FileChangeRequest = 1;
		//	}
		//	break;
		default:
			break;
	}
}

void LC786XXX_SetBitRate(void)
{
	if  (ucLC786XXX_CurrentMediaID == LC786X_USB)
	{
		sUSB_PlayInfo.BitRate = usLC786XXX_PlayBitRate;
		USB_SetTextStatus(UI_TEXT_READY_BITRATE);
	}
#ifdef  LC78696X
	if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
	{
		sCD_PlayInfo.BitRate = usLC786XXX_PlayBitRate;
		CD_SetTextStatus(UI_TEXT_READY_BITRATE);
	}
#endif
}

void LC786XXX_ClearNameDisplayTimer(void)
{
	ucDISP_FileName = 0;
	ucDISP_FolderName = 0;
}

void LC786XXX_ScanFileChange(void)
{
	DRV_LC786XXX_Skip_SkipFolder(0x00);
//	DISP_PageScrollReset();
	ucLC786XXX_FileChangeRequest = 1;
}

void LC786XXX_USB_RepeatFileCheck(void)
{
	if  (ucUSB_Repeat == REPEAT_FILE)
	{
		switch  (ucLC786XXX_USB_Status)
		{
			case LC786X_MS_PAUSE_AT_HEADER_OF_TRACK:
				if  (USB_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
				{
					USB_RepeatOff();
					//DRV_LC786XXX_SetPlayOrder(0x40);
					USB_FastBackwardStart();
				}
				break;
			case LC786X_MS_PAUSE_AT_END_OF_TRACK:
				if  (USB_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				{
					USB_RepeatOff();
					//DRV_LC786XXX_SetPlayOrder(0x40);
					USB_FastForwardStart();
				}
				//if  (USB_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
				//{
				//	USB_FastBackwardStart();
				//}
				break;
			case LC786X_MS_PAUSE_AT_HEADER_OF_FOLDER:
				//if  (USB_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				//{
				//	USB_FastForwardStart();
				//}
				if  (USB_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
				{
					USB_RepeatOff();
					//DRV_LC786XXX_SetPlayOrder(0x40);
					USB_FastBackwardStart();
				}
				break;
			case LC786X_MS_PAUSE_AT_END_OF_FOLDER:
				if  (USB_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				{
					USB_RepeatOff();
					//DRV_LC786XXX_SetPlayOrder(0x40);
					USB_FastForwardStart();
				}
				break;
//			case LC786X_MS_PAUSE_AT_HEADER_OF_DISC:
//				if  (USB_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
//				{
//					USB_FastForwardStart();
//				}
//				if  (USB_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
//				{
//					USB_RepeatOff();
//					DRV_LC786XXX_SetPlayOrder(0x40);
//					USB_FFREW_Release();
//				}
//				break;
			case LC786X_MS_PAUSE_AT_END_OF_DISC:
				if  (USB_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				{
					USB_RepeatOff();
					//DRV_LC786XXX_SetPlayOrder(0x40);
					USB_FastForwardStart();
				}
				break;
		}

		return;
	}
	
	if  (ucUSB_Repeat == REPEAT_FOLDER)
	{
		switch  (ucLC786XXX_USB_Status)
		{
			//case LC786X_MS_PAUSE_AT_HEADER_OF_TRACK:
			//	if  (USB_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
			//	{
			//		USB_RepeatOff();
			//		DRV_LC786XXX_SetPlayOrder(0x40);
			//		USB_FastBackwardStart();
			//	}
			//	break;
			//case LC786X_MS_PAUSE_AT_END_OF_TRACK:
			//	if  (USB_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
			//	{
			//		USB_FastForwardStart();
			//	}
			//	if  (USB_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
			//	{
			//		USB_FastBackwardStart();
			//	}
			//	break;
			case LC786X_MS_PAUSE_AT_HEADER_OF_FOLDER:
				if  (USB_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
				{
					USB_RepeatOff();
					//DRV_LC786XXX_SetPlayOrder(0x40);
					USB_FastBackwardStart();
				}
				break;
			case LC786X_MS_PAUSE_AT_END_OF_FOLDER:
				if  (USB_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				{
					USB_RepeatOff();
					//DRV_LC786XXX_SetPlayOrder(0x40);
					USB_FastForwardStart();
				}
				break;
//			case LC786X_MS_PAUSE_AT_HEADER_OF_DISC:
//				if  (USB_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
//				{
//					USB_RepeatOff();
//					DRV_LC786XXX_SetPlayOrder(0x40);
//					USB_FFREW_Release();
//				}
//				break;
			case LC786X_MS_PAUSE_AT_END_OF_DISC:
				if  (USB_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				{
					USB_RepeatOff();
					//DRV_LC786XXX_SetPlayOrder(0x40);
					USB_FastForwardStart();
				}
				break;
		}

		return;
	}
}

#ifdef  LC78696X

void LC786XXX_CD_RepeatFileCheck(void)
{
	LC786X_MEDIA_STATUS	Status;
	
	if  (ucCD_Repeat == REPEAT_FILE)
	{
		Status = LC786XXX_GetMediaStatus(FUNC_CD);
		switch  (Status)
		{
			case LC786X_MS_PAUSE_AT_HEADER_OF_TRACK:
				if  (CD_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
				{
					CD_RepeatOff();
				//	DRV_LC786XXX_SetPlayOrder(0x40);
					CD_FastBackwardStart();
				}
				break;
			case LC786X_MS_PAUSE_AT_END_OF_TRACK:
				if  (CD_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				{
					CD_RepeatOff();
				//	DRV_LC786XXX_SetPlayOrder(0x40);
					CD_FastForwardStart();
				}
				//if  (CD_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
				//{
				//	CD_FastBackwardStart();
				//}
				break;
			case LC786X_MS_PAUSE_AT_HEADER_OF_FOLDER:
				//if  (CD_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				//{
				//	CD_FastForwardStart();
				//}
				if  (CD_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
				{
					CD_RepeatOff();
				//	DRV_LC786XXX_SetPlayOrder(0x40);
					CD_FastBackwardStart();
				}
				break;
			case LC786X_MS_PAUSE_AT_END_OF_FOLDER:
				if  (CD_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				{
					CD_RepeatOff();
				//	DRV_LC786XXX_SetPlayOrder(0x40);
					CD_FastForwardStart();
				}
				break;
//			case LC786X_MS_PAUSE_AT_HEADER_OF_DISC:
//				if  (CD_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
//				{
//					CD_FastForwardStart();
//				}
//				if  (CD_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
//				{
//					CD_RepeatOff();
//					DRV_LC786XXX_SetPlayOrder(0x40);
//					CD_FFREW_Release();
//				}
//				break;
			case LC786X_MS_PAUSE_AT_END_OF_DISC:
				if  (CD_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				{
					CD_RepeatOff();
				//	DRV_LC786XXX_SetPlayOrder(0x40);
					CD_FastForwardStart();
				}
				break;
		}

		return;
	}
	
	if  (ucCD_Repeat == REPEAT_FOLDER)
	{
		Status = LC786XXX_GetMediaStatus(FUNC_CD);
		switch  (Status)
		{
		//	case LC786X_MS_PAUSE_AT_HEADER_OF_TRACK:
		//		if  (CD_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
		//		{
		//			CD_RepeatOff();
		//			DRV_LC786XXX_SetPlayOrder(0x40);
		//			CD_FastBackwardStart();
		//		}
		//		break;
		//	case LC786X_MS_PAUSE_AT_END_OF_TRACK:
		//		if  (CD_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
		//		{
		//			CD_FastForwardStart();
		//		}
		//		if  (CD_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
		//		{
		//			CD_FastBackwardStart();
		//		}
		//		break;
			case LC786X_MS_PAUSE_AT_HEADER_OF_FOLDER:
				if  (CD_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
				{
					CD_RepeatOff();
		//			DRV_LC786XXX_SetPlayOrder(0x40);
					CD_FastBackwardStart();
				}
				break;
			case LC786X_MS_PAUSE_AT_END_OF_FOLDER:
				if  (CD_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				{
					CD_RepeatOff();
		//			DRV_LC786XXX_SetPlayOrder(0x40);
					CD_FastForwardStart();
				}
				break;
//			case LC786X_MS_PAUSE_AT_HEADER_OF_DISC:
//				if  (CD_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
//				{
//					CD_RepeatOff();
//					DRV_LC786XXX_SetPlayOrder(0x40);
//					CD_FFREW_Release();
//				}
//				break;
			case LC786X_MS_PAUSE_AT_END_OF_DISC:
				if  (CD_GetFastPlayStatus() == MEDIA_FAST_FORWARD_PLAY)
				{
					CD_RepeatOff();
		//			DRV_LC786XXX_SetPlayOrder(0x40);
					CD_FastForwardStart();
				}
				break;
		}

		return;
	}
}

#endif

void LC786XXX_MediaStatusCheck_USB(void)
{
	if  (ucLC786XXX_USB_Process != LC786XXX_PROCESS_NORMAL)
	{
		return;
	}

	if  (ucLC786XXX_USB_Status == LC786X_MS_DEVICE_DISCONNECT)
	{
		return;
	}
	
	if  ((sUSB_PlayInfo.Hour != ucLC786XXX_PlayHour)
		|| (sUSB_PlayInfo.Min != ucLC786XXX_PlayMin)
		|| (sUSB_PlayInfo.Sec != ucLC786XXX_PlaySec))
	{
		LOG_USB("USB PLAY:%d,%d",sUSB_PlayInfo.FolderNo,sUSB_PlayInfo.FileNo);
		LOG_USB("%d:%d:%d",ucLC786XXX_PlayHour,ucLC786XXX_PlayMin,ucLC786XXX_PlaySec);
	}
	sUSB_PlayInfo.Hour = ucLC786XXX_PlayHour;
	sUSB_PlayInfo.Min = ucLC786XXX_PlayMin;
	sUSB_PlayInfo.Sec = ucLC786XXX_PlaySec;
	
	ucUSB_Resume = 1;
	
	if  ((ucLC786XXX_FileChangeRequest == 0) && (ucUSB_Scan != SCAN_NONE))
	{
		if  ((ucLC786XXX_PlayHour == 0) && (ucLC786XXX_PlayMin == 0) && (ucLC786XXX_PlaySec > 9))
		{
			LC786XXX_ScanFileChange();			
		//	USB_ClearTextStatus(0xFF);
		}
	}
	if  (sUSB_PlayInfo.FileNo != ulLC786XXX_PlaySerialNo)
	{
		ucDISP_FileName = 1;
		ucDISP_FileName_Timer50msec = 5000/50;
	}
	if	(sUSB_PlayInfo.FolderNo != usLC786XXX_PlayFolderNo)
	{
		ucDISP_FolderName = 1;
		ucDISP_FolderName_Timer50msec = 5000/50;
		ucDISP_FileName_Timer50msec = 10000/50;
		DRV_LC786XXX_GetTotalMediaFile(LC786X_USB,0x01,usLC786XXX_PlayFolderNo);
	}  

	if  ((sUSB_PlayInfo.FolderNo != usLC786XXX_PlayFolderNo) || (sUSB_PlayInfo.FileNo != ulLC786XXX_PlaySerialNo))
	{			
		ucLC786XXX_FileChangeRequest = 0;

		if  (sUSB_PlayInfo.FolderNo == usLC786XXX_PlayFolderNo)
		{
			ucDISP_FolderName = 0;
			ucDISP_FolderName_Timer50msec = 0;
		}
		sUSB_PlayInfo.FolderNo = usLC786XXX_PlayFolderNo;
		sUSB_PlayInfo.FileNo = ulLC786XXX_PlaySerialNo;//usLC786XXX_PlayFileNo;
				
		if  (ulLC786XXX_PlaySerialNo != 0)
		{
			LC786XXX_GetTextStart();
		}
	//	ucLC786XXX_Process_10msecTimer = 800/10;
		ucLC786XXX_MediaStatusCheck_10msecTimer = 0;

		if  (ucUSB_Scan != SCAN_NONE)
		{
			if  (usUSB_ScanFileNumber == ulLC786XXX_PlaySerialNo)
			{
				USB_ScanOff();
			}
		}
		AUDIO_SetMute(4);
		DISP_ClearTempDisplayMode();
		MENU_Clear();
		DISP_SetCurrentDisplay();
		USB_ClearTextStatus(0xFF);
		LOG_USB("FileNumber:%d",sUSB_PlayInfo.FileNo);
	}
	
	if  (ucLC786XXX_USB_Status == LC786X_MS_PAUSE_AT_HEADER_OF_DISC) 
	{
		if  (USB_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
		{
			if  (ucUSB_Repeat != REPEAT_NONE)
			{
				USB_RepeatOff();
			}
			USB_FFREW_Release();
		}
	}

	LC786XXX_USB_RepeatFileCheck();
	LC786XXX_RandomStatusCheck_USB();
	LC786XXX_GetText_Process(FUNC_USB);
}

#ifdef	LC78696X
void LC786XXX_RandomStatusCheck_CD(void)
{
	LC786X_MEDIA_STATUS Status;

	if  (ucCD_Random == RANDOM_NONE)
	{
		return;
	}
	
	if  (ucLC786XXX_FileChangeRequest == 1)
	{
		return;
	}
	Status = LC786XXX_GetMediaStatus(FUNC_CD);

	switch  (Status)
	{
		case LC786X_MS_PLAYBACK:
		case LC786X_MS_SEARCH:
		case LC786X_MS_PAUSE:
		case LC786X_MS_FASTFORWARD:
		case LC786X_MS_FASTBACK:
			//
			break;
		case LC786X_MS_PAUSE_AT_END_OF_TRACK:
		case LC786X_MS_PAUSE_AT_END_OF_FOLDER:
		case LC786X_MS_PAUSE_AT_END_OF_DISC:
			if  (CD_GetFastPlayStatus() == MEDIA_NORMAL_PLAY)
			{
				CD_RandomFileChange(1);
				ucLC786XXX_FileChangeRequest = 1;
			}
			break;
		case LC786X_MS_PAUSE_AT_HEADER_OF_TRACK:
			if  (CD_GetFastPlayStatus() == MEDIA_NORMAL_PLAY)
			{
				CD_RandomFileChange(1);
				ucLC786XXX_FileChangeRequest = 1;
			}
			break;
		case LC786X_MS_PAUSE_AT_HEADER_OF_FOLDER:
			if  (CD_GetFastPlayStatus() == MEDIA_NORMAL_PLAY)
			{
				CD_RandomFileChange(1);
				ucLC786XXX_FileChangeRequest = 1;
			}
	//	case LC786X_MS_PAUSE_AT_HEADER_OF_DISC:
	//		if  (CD_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
	//		{
	//			CD_FFREW_Release();
	//		}
	//		else  
	//		if  (CD_GetFastPlayStatus() == MEDIA_NORMAL_PLAY)
	//		{
	//			CD_RandomFileChange(1);
	//			ucLC786XXX_FileChangeRequest = 1;
	//		}
	//		break;
		default:
			break;
	}

}

void LC786XXX_MediaStatusCheck_CD(void)
{
	if  (ucLC786XXX_CD_Process != LC786XXX_PROCESS_NORMAL)
	{
		return;
	}

#ifdef  DEBUG_UART
	if  ((sCD_PlayInfo.Hour != ucLC786XXX_PlayHour)
		|| (sCD_PlayInfo.Min != ucLC786XXX_PlayMin)
		|| (sCD_PlayInfo.Sec != ucLC786XXX_PlaySec))
	{
		if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
		{
			LOG_CD("CDDA:%d:%d:%d",ucLC786XXX_PlayHour,ucLC786XXX_PlayMin,ucLC786XXX_PlaySec);
		}
		if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
		{
			LOG_CD("CDROM:D%d,F%d",sCD_PlayInfo.FolderNo,sCD_PlayInfo.FileNo);
			LOG_CD("%d:%d:%d",ucLC786XXX_PlayHour,ucLC786XXX_PlayMin,ucLC786XXX_PlaySec);
		}
	}
#endif
	sCD_PlayInfo.Hour = ucLC786XXX_PlayHour;
	sCD_PlayInfo.Min = ucLC786XXX_PlayMin;
	sCD_PlayInfo.Sec = ucLC786XXX_PlaySec;
	ucCD_Resume = 1;

	if  (ucLC786XXX_CurrentMediaID == LC786X_CDROM)
	{
#ifdef  DEBUG_UART
		if  ((sCD_PlayInfo.Hour != ucLC786XXX_PlayHour)
			|| (sCD_PlayInfo.Min != ucLC786XXX_PlayMin)
			|| (sCD_PlayInfo.Sec != ucLC786XXX_PlaySec))
		{
			LOG_LC786("CDROM:D%d,F%d",sCD_PlayInfo.FolderNo,sCD_PlayInfo.FileNo);
			LOG_LC786("%d:%d:%d",ucLC786XXX_PlayHour,ucLC786XXX_PlayMin,ucLC786XXX_PlaySec);
		}
#endif
		if  (ucCD_CurrentPlayDiscType == CD_DISC_CDDA)
		{
			LC786XXX_GetTextStart();
			ucDISP_FolderName = 1;			
			ucDISP_FolderName_Timer50msec = 3000/50;
		}
		ucCD_CurrentPlayDiscType = CD_DISC_CDROM;
	}
	if  (ucLC786XXX_CurrentMediaID == LC786X_CDDA)
	{
#ifdef  DEBUG_UART
		if  ((sCD_PlayInfo.Hour != ucLC786XXX_PlayHour)
			|| (sCD_PlayInfo.Min != ucLC786XXX_PlayMin)
			|| (sCD_PlayInfo.Sec != ucLC786XXX_PlaySec))
		{
			LOG_LC786("CDDA:%d:%d:%d",ucLC786XXX_PlayHour,ucLC786XXX_PlayMin,ucLC786XXX_PlaySec);
		}
#endif
		if  (ucCD_CurrentPlayDiscType == CD_DISC_CDROM)
		{
			LC786XXX_GetTextStart();
		}
		ucCD_CurrentPlayDiscType = CD_DISC_CDDA;
		ucDISP_FolderName = 0;
	}

	if  ((ucLC786XXX_FileChangeRequest == 0) && (ucCD_Scan != SCAN_NONE))
	{
		if  ((ucLC786XXX_PlayHour == 0) && (ucLC786XXX_PlayMin == 0) && (ucLC786XXX_PlaySec > 9))
		{
			LC786XXX_ScanFileChange();
	//		CD_ClearTextStatus(0xFF);
		}
	}

	if  (sCD_PlayInfo.FileNo != ulLC786XXX_PlaySerialNo)
	{
		ucDISP_FileName = 1;
		ucDISP_FileName_Timer50msec = 3000/50;
	}
	
	if	(sCD_PlayInfo.FolderNo != usLC786XXX_PlayFolderNo)
	{	
		DRV_LC786XXX_GetTotalMediaFile(LC786X_CDROM,0x01,usLC786XXX_PlayFolderNo);
		ucDISP_FolderName = 1;
		ucDISP_FolderName_Timer50msec = 3000/50;
		ucDISP_FileName_Timer50msec = 6000/50;
	}
	
	if  ((sCD_PlayInfo.FolderNo != usLC786XXX_PlayFolderNo) || (sCD_PlayInfo.FileNo != ulLC786XXX_PlaySerialNo))
	{
		ucLC786XXX_FileChangeRequest = 0;
		LC786XXX_GetTextStart();
		ucLC786XXX_MediaStatusCheck_10msecTimer = 0;
				
		if  (sCD_PlayInfo.FolderNo == usLC786XXX_PlayFolderNo)
		{
			ucDISP_FolderName = 0;
			ucDISP_FolderName_Timer50msec = 0;
		}
		
		sCD_PlayInfo.FolderNo = usLC786XXX_PlayFolderNo;
		sCD_PlayInfo.FileNo = ulLC786XXX_PlaySerialNo;
		
		if  (ucCD_Scan != SCAN_NONE)
		{
			if  (usCD_ScanFileNumber == ulLC786XXX_PlaySerialNo)
			{
				CD_ScanOff();
			}
		}
		AUDIO_SetMute(4);
		CD_ClearTextStatus(0xFF);
		DISP_ClearTempDisplayMode();
		MENU_Clear();
		DISP_SetCurrentDisplay();
	}

	if  ((ucLC786XXX_CDROM_Status == LC786X_MS_PAUSE_AT_HEADER_OF_DISC)
		|| (ucLC786XXX_CDDA_Status == LC786X_MS_PAUSE_AT_HEADER_OF_DISC)) 
	{
		if  (CD_GetFastPlayStatus() == MEDIA_FAST_BACKWARD_PLAY)
		{
			if  (ucCD_Repeat != REPEAT_NONE)
			{
				CD_RepeatOff();
			}
			CD_FFREW_Release();
		}
	}

	LC786XXX_CD_RepeatFileCheck();
	LC786XXX_RandomStatusCheck_CD();
	LC786XXX_GetText_Process(FUNC_CD);
}
#endif


void LC786XXX_Main(void)	// 40msec
{	
//	if  ((ucLC786XXX_SPI_ReceiveSeq != LC786XXX_RSPI_IDLE)
//		|| (ucLC786XXX_SPI_SendSeq != LC786XXX_SPI_S_IDLE))
//	{
//		return;
//	}

	if  (DRV_LC786XXX_SerialIdle() == 0)
	{
		return;
	}
	if  ((DRV_LC786XXX_SendBufferStatus() == 1) || (DRV_LC786XXX_ReadBufferStatus() == 1))
	{
		return;
	}
	
	LC786XXX_ErrorCodeCheck(ucLC786XXX_CurrentMediaID);
	if  (ucLC786XXX_InitializeComplete == 0)
	{		
	//	LC786XXX_Initialize();
	}
	else
	{
		if  (ucLC786XXX_MediaStatusCheck_10msecTimer == 0)
		{
			DRV_LC786XXX_GetCurrentMediaStatus(0x00);
			ucLC786XXX_MediaStatusCheck_10msecTimer = 200/10;
		}
		LC786XXX_USB_DetectMain();
		LC786XXX_USBFunctionProcess();
		LC786XXX_MediaStatusCheck_USB();
	#ifdef  LC78696X
		LC786XXX_CDFunctionProcess();
		LC786XXX_MediaStatusCheck_CD();
	#endif
	}
}
#endif


